From owner-freebsd-arch Mon Jul 9 5:59: 3 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id B637A37B403 for ; Mon, 9 Jul 2001 05:58:57 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id WAA19888; Mon, 9 Jul 2001 22:58:50 +1000 Date: Mon, 9 Jul 2001 22:56:45 +1000 (EST) From: Bruce Evans X-Sender: bde@besplex.bde.org To: Harti Brandt Cc: arch@FreeBSD.ORG Subject: Re: -fno-builtin In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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