Re: GCC-4.0 warnings

Hello, Roland!

On Wed, 2005-05-18 at 21:46 +0200, Roland Illig wrote:
> Leonard den Ottolander wrote:
> > Hi,
> > 
> > Here's a list of gcc-4.0 warnings against HEAD from 2005-05-04. Tarball
> > taken from the FC4t3 mc-4.6.1a-0.9.src.rpm. Removed all patches as not
> > to cause confusion between clean CVS and downstream patches. Grepped for
> > "warning" in the build log.
> Thanks for the list.
> If anyone wants to fix these warnings, please _think_ before committing. 
> Changing a variable from signed to unsigned or vice versa is not a 
> trivial thing.

Another thing.  It turns out gcc 4.0.0 is smart enough to check logic in
the called function if it's available.  This means that it may warn
about uninitialized variables if they were passed to a function that
doesn't always initialize them.

So you can get a warning in this situation:

int callee(int *out)
   if (bad_things)
      return -1;
   *out = 1;
   return 0;

void caller(void)
    int val;

    if (callee(&val) < 0)

    printf("%d\n", val);

The warning is shown only if callee() is defined in the same file, so
that gcc can check it.  You may need use -O3 flag to get the warning (I
guess it tells gcc to use inlining more aggressively).

While the code is correct, it's not obvious for gcc.  The "knee-jerk"
reaction could be to initialize val in caller(), but sometimes it may be
better to fix callee(), especially if it's used many times.  Even more
so if it's not documented that the pointer won't be initialized if
callee() returns a failure code.

I have fixed all warnings in HEAD except one introduced by you.  I guess
you can fix it better (I tried and it's not trivial, so you may want to
reverse some of your changes instead):

help.c: In function 'help_handle_key':
help.c:627: warning: passing argument 3 of 'check_movement_keys'
discards qualifiers from pointer target type

Pavel Roskin

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]