🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #314

Misleading (IMHO) warning in GCC v2.2 on all platforms

#314
From: Erik Talvola
Date: Fri, 07 Aug 1992 02:59
38 lines
1934 bytes
The following program:

#include <stdio.h>

char sample[10] = "Hello\n";

void test2(char *param)
{
  printf(param);
}

void main()
{
  test2(sample);
  test2(&sample);
  test2((char *) &sample);
}

generates a warning on the second call to test2.  It says:

gcc version 2.2.2
 /usr/sww/lib/gcc-lib/sun4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix gcctest2.c /usr/tmp/cca20551.i
GNU CPP version 2.2.2 (sparc)
 /usr/sww/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca20551.i -quiet -dumpbase gcctest2.c -version -o /usr/tmp/cca20551.s
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
gcctest2.c: In function `main':
gcctest2.c:13: warning: passing arg 1 of `test2' from incompatible pointer type
 as -o gcctest2.o /usr/tmp/cca20551.s
 /usr/sww/lib/gcc-lib/sun4/2.2.2/ld -e start -dc -dp /lib/crt0.o -L/usr/sww/lib/gcc-lib/sun4/2.2.2 -L/usr/sww/lib gcctest2.o -lgcc -lc -lgcc

In my opinion, this warning is misleading.  All three of the different
calls to test2 are passed the same thing - the address of the first
character of the array 'sample', and if you run the program, it works
perfectly.  The warning should probably be changed to say something
like "superfluous & before array name" or something like that (this is
what the SCO compiler gives as a warning).  Actually, the warning
should probably not even occur unless some extra -W flag is specified,
because the code is perfectly legal.  
Technical Details
Message-ID: <9208070259.AA20558@qin.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!qin.berkeley.edu!talvola

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!qin.berkeley.edu!talvola
From: talvola@qin.berkeley.edu (Erik Talvola)
Subject: Misleading (IMHO) warning in GCC v2.2 on all platforms
Message-ID: <9208070259.AA20558@qin.Berkeley.EDU>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 7 Aug 1992 02:59:39 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 41