From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: Ralph Corderoy Message-ID: References: <4da3d9af.0203131248.60d6899e@posting.google.com>, <3C914E64.D5D00447@null.net>, <4da3d9af.0203150929.1d3154d2@posting.google.com> Subject: Re: macro fun [Re: [9fans] plan or side effect] Date: Mon, 18 Mar 2002 10:33:35 +0000 Topicbox-Message-UUID: 689265b8-eaca-11e9-9e20-41e7f4b1d025 Hi ozan, > > > i'll let you figure out what t.c trivially contains to make a soup > > > with the "optimized" macro, thanks to simple textual substitution. > > > > Is t.c a strictly conforming program? If not, you got what you asked > > for. > > according to gcc, it is strictly conforming. it compiles > perfectly. here is more strict version: > > bent!oz| gcc -Wall -ansi -pedantic -o t t.c > bent!oz| ./t > hello boyd! > > now, with -O > > bent!oz| gcc -O -Wall -ansi -pedantic -o t t.c > t.c:4: parse error before `__extension__' > > this is absolute crap. here is t.c. In this case, it is t.c that's crap. > #include > #include > > extern char *strcpy(char *, const char *); You can't do that in ANSI C and expect not to get bitten. The compiler is allowed to implement a standard library function as a macro if they wish, but must still implement it as a function so its address can be taken. If you wish to refer to the function, without knowing if a macro exists, you are meant to do either #ifdef strcpy #undef strcpy #endif or extern char *(strcpy)(char *, const char *); See a book like Harbison and Steele's _C, A Reference Manual_ for more info on writing compliant source. IBM's AIX C compiler also #defines strcpy as an optimisation. $ cc -qlanglvl=ansi -E t.c | grep strcpy extern char *strcpy(char *, const char *); extern char *__strcpy(char *,const char *); __strcpy(buf,"hello boyd!"); So that doesn't give the effect you intended either. Cheers, Ralph.