int main( int argc, char **argv ) {
int i, a, x;
a = rand();
if ( a ) {
i = 1;
x = 0;
} else {
i = 0;
}
if ( i ) printf ("%d\n", x);
exit (0);
}
gcc -Wall prints: warning: `x' might be used uninitialized in
this function
IMHO it may not be used uninitialized. Am I missing something?
Please explain this to me.
Simply add x=0; at the beginning to avoid this warning doesn't
seem to be correct.
Radim. Maybe I'm missing something, but, what do you expect from 'x'
in the else case?. What is the purpouse of 'x' variable in general?
>
> int main( int argc, char **argv ) {
> int i, a, x;
> a = rand();
> if ( a ) {
> i = 1;
> x = 0;
> } else {
> i = 0;
> }
> if ( i ) printf ("%d\n", x);
> exit (0);
> }
>
> gcc -Wall prints: warning: `x' might be used uninitialized in
> this function
> IMHO it may not be used uninitialized. Am I missing something?
> Please explain this to me.
> Simply add x=0; at the beginning to avoid this warning doesn't
> seem to be correct.
Radim. Maybe I'm missing something, but, what do you expect from 'x'
in the else case?. What is the purpouse of 'x' variable in general?
[experimental d.legend code- you can check my use of G_calloc while
you're at it :)]
It should get initialized both sides of the 'if' as far as I can tell, but
the compiler isn't so sure.
One might init a variable to -1, which for a something like a counter
variable or a category value would immediately indicate something was
wrong when seen after it should already 'exist'..
Gets rid of the warning anyway.
Of course that wouldn't work of course for variables that could sensibly
have a value of -1.
On Thursday 08 May 2003 11:40 am, GFernandez-Victorio@IGAE.minhac.es wrote:
> int main( int argc, char **argv ) {
> int i, a, x;
> a = rand();
> if ( a ) {
> i = 1;
> x = 0;
> } else {
> i = 0;
> }
> if ( i ) printf ("%d\n", x);
> exit (0);
> }
>
> gcc -Wall prints: warning: `x' might be used uninitialized in
> this function
> IMHO it may not be used uninitialized. Am I missing something?
> Please explain this to me.
> Simply add x=0; at the beginning to avoid this warning doesn't
> seem to be correct.
Radim. Maybe I'm missing something, but, what do you expect from 'x'
in the else case?. What is the purpouse of 'x' variable in general?
It was just a test what that warning means - explained by Glynn.