[GRASS5] GRASS 5.1 v.in.ascii bug

H Bowman hamish_nospam at yahoo.com
Thu May 8 06:33:55 EDT 2003


> > 
> > 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?


For a real world example, examine the 'catlist' variable in:
http://bambi.otago.ac.nz/hamish/main.c.withUSE10

[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.



Hamish




More information about the grass-dev mailing list