greim@sbsvax.UUCP (Michael Greim) (07/19/89)
Hello, I tried the following program on several machines. IMHO the program should not compile yet there are some compilers which compile it: cc 43bsd cc 43bsd-tahoe cc ultrix 2.0 cc SunOS 3.5 And there are some that give an error message: gcc 1.34 cc sinix 2.1 ("McClure") Here is the program: ---------- cut here ---------------------------- /* * What does the compiler do with this? */ # include <stdio.h> struct link { struct link * next; int count; }; int fix0; struct link * t; int fix1; main () { printf ("t lies at %1d, brk is at %1d\n", (int)(&t), (int)sbrk(0)); printf ("Addresses of %1d byte objects around t : %1d and %1d\n", sizeof(int), (int)(&fix0), (int)(&fix1)); t = NULL; t.count = 5; if (t.count == 5) printf ("Assignment worked.\n"); else printf ("Assignment did not work\n"); printf ("Value 5 has been put at address %1d\n", &(t.count)); } ---------- cut here ---------------------------- Output from VAX running 43bsd: Script started on Wed Jul 19 11:44:22 1989 % cc test78.c "test78.c", line 21: warning: struct/union or struct/union pointer required "test78.c", line 22: warning: struct/union or struct/union pointer required "test78.c", line 26: warning: struct/union or struct/union pointer required % a.out t lies at 6008, brk is at 6176 Addresses of 4 byte objects around t : 6004 and 6012 Assignment worked. Value 5 has been put at address 6012 % exit % script done on Wed Jul 19 11:44:47 1989 Am I correct to say that the program is not correct C, and that all compilers which compile it are wrong? -mg -- Michael Greim Email : greim@sbsvax.informatik.uni-saarland.dbp.de or : ...!uunet!unido!sbsvax!greim [.signature removed by the board of censors for electronic mail's main executive computer because it contained a four letter word ("word")]