`interesting' program
Maarten Litmaath
maart at cs.vu.nl
Fri Jul 7 14:03:20 AEST 1989
----------8<----------8<----------8<----------8<----------8<----------
/* Any comments? */
struct foo {
int mids;
};
struct foo zork()
{
struct foo foo;
foo.mids = 79;
return foo;
}
/*
* Try:
* cc -DFOO foo.c
* cc -DBAR foo.c
* cc foo.c
* gcc -DFOO foo.c
* gcc -DBAR foo.c
* gcc foo.c
*
* and compare!
*/
main()
{
#if !FOO && !BAR
struct foo bar;
bar = zork();
#endif
printf("%d\n",
#if FOO
zork().mids
#else
#if BAR
(&zork())->mids
#else
bar.mids
#endif
#endif
);
}
----------8<----------8<----------8<----------8<----------8<----------
Results:
1) Sun 3/50 w/ SunOS 3.5 cc dislikes FOO, likes BAR
2) Sun 3/50 w/ SunOS 3.5 gcc 1.32 likes FOO, dislikes BAR
3) Sun 4/280 w/ SunOS Sys4-3.2 cc likes FOO, likes BAR
IMHO 2) is the winner! ISEHO 3) is right.
I say: zork() is a constant of type struct foo, so you cannot take its
address and it isn't an lvalue.
SE says: zork() is the name of a struct foo, so you CAN take its address.
--
"I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam:
they're small." (Stephen Savitzky) |maart at cs.vu.nl, mcvax!botter!maart
More information about the Comp.lang.c
mailing list