🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Erik Talvola Fri, 07 Aug 1992 02:59
Misleading (IMHO) warning in GCC v2.2 on all platforms
#314
Author: 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.  
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads