Re: Linked List



On 2009-11-27, Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:
In which case, I think I've found (or at least, this thread may have
revealed) a bug in gcc. Here's my sample program, with enough added
to ensure that gcc can't even pretend that the CV doesn't matter (not
that I think it could anyway, but I wanted to avoid any "as if"
nonsense right at the outset):

$ cat foo.c
#include <stdio.h>

int main(void)
{
struct node
{
struct node *next;
} this = { &this };
printf("%p\n", this.next);

Oops, where is the warning about non-void-* being passed to %p?
Maybe you're not using glibc, which has the right annotations in the
headers.

return 0;
}
$ make
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-ffloat-store -O2 -fno-builtin -g -pg -c -o foo.o foo.c

But you didn't say ``be a c89 compiler''. The code is being treated
as c99.

Also, reports about gcc behavior are not all that informative without the
version.

[fedora@localhost ~]$ gcc -Wall -ansi -pedantic -std=c89 test.c
test.c: In function ‘main’:
test.c:8: warning: initializer element is not computable at load time
test.c:9: warning: format ‘%p’ expects type ‘void *’, but argument 2 has type ‘struct node *’

[fedora@localhost ~]$ gcc --version
gcc (GCC) 4.4.0 20090506 (Red Hat 4.4.0-4)
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[fedora@localhost ~]$ gcc -Wall -ansi -pedantic -std=c99 test.c
test.c: In function ‘main’:
test.c:9: warning: format ‘%p’ expects type ‘void *’, but argument 2 has type ‘struct node *’


This is not particularly new:


[rhel4@localhost ~]$ gcc -Wall -ansi -pedantic test.c
test.c: In function `main':
test.c:8: warning: initializer element is not computable at load time
test.c:9: warning: void format, node arg (arg 2)
[rhel4@localhost ~]$ gcc --version
gcc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.1)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.



Relevant Pages