N
Nick
I've just started to get a strange warning from GCC. Can you check my
code for me and check that this is GCC being silly - and so it should be
reported as a bug - not me missing something.
Here's a cut-down example:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *s;
char *a = "this is + some stuff";
for(s=a; s && *s; s && ++s) {
printf("[%c]",*s);
if(*s == '+')
s = NULL;
}
printf("\n");
return 0;
}
OK, not very elegant, but setting the pointer to null part way through
to abort the loop should work (I know I could use "break" - the real
example is more complicated).
It's that "s && ++s" in the third stanza of the for() that's causing the
problems. GCC complains "value computed is not used". That's true of
course, but the same is true of the traditional "++s". I can get round
it by casting that expression to void but surely I shouldn't need to do
this.
I see a few bug reports floating round of GCC being over-zealous with
this report in the latest version. So is my code fine, in which case
I'll complain about GCC, or should any decent compiler be complaining
about it (and in which case, for my education, why?)?
code for me and check that this is GCC being silly - and so it should be
reported as a bug - not me missing something.
Here's a cut-down example:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *s;
char *a = "this is + some stuff";
for(s=a; s && *s; s && ++s) {
printf("[%c]",*s);
if(*s == '+')
s = NULL;
}
printf("\n");
return 0;
}
OK, not very elegant, but setting the pointer to null part way through
to abort the loop should work (I know I could use "break" - the real
example is more complicated).
It's that "s && ++s" in the third stanza of the for() that's causing the
problems. GCC complains "value computed is not used". That's true of
course, but the same is true of the traditional "++s". I can get round
it by casting that expression to void but surely I shouldn't need to do
this.
I see a few bug reports floating round of GCC being over-zealous with
this report in the latest version. So is my code fine, in which case
I'll complain about GCC, or should any decent compiler be complaining
about it (and in which case, for my education, why?)?