Date: Mon, 9 Jul 2001 22:56:45 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Harti Brandt <brandt@fokus.gmd.de> Cc: arch@FreeBSD.ORG Subject: Re: -fno-builtin Message-ID: <Pine.BSF.4.21.0107092242340.87868-100000@besplex.bde.org> In-Reply-To: <Pine.BSF.4.33.0107091420430.17758-100000@beagle.fokus.gmd.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 9 Jul 2001, Harti Brandt wrote: > On Mon, 9 Jul 2001, Bruce Evans wrote: > > BE>I think it would work right except in broken code which "knows" that > BE>strlen isn't a macro, e.g.: > BE> > BE> size_t (*p)(const char *s) = strlen; > > Why is that broken? My last copy of the ISO-C draft specifically states, > that strlen is a function. (Not that I intend to use that construct. Just > beeing curious). Does it really? Almost any library function can be implemented as a (safe) macro (see section 7.1.4). I can't find any exception for strlen. This possibility is not completely transparent to applications. Code like the above should be aware of it. Workarounds are easy in the above (just used "&strlen" or "(strlen)". Section 7.1.4 documents these. Howver, I now remember a nasty example which shows why implementations should not do this: len = strlen( #ifdef FOO "foo" #else "default" #endif ); This causes errors like: z.c:11: warning: preprocessing directive not recognized within macro arg z.c:11: warning: preprocessing directive not recognized within macro arg z.c:11: warning: preprocessing directive not recognized within macro arg z.c: In function `main': z.c:6: undefined or invalid # directive z.c:8: undefined or invalid # directive z.c:10: undefined or invalid # directive I only learned of this example a weeks or two ago. gcc-3.0 was reported to make a very fundamental function (printf?) a macro. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0107092242340.87868-100000>