Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jul 2001 15:56:29 +0200 (CEST)
From:      Harti Brandt <brandt@fokus.gmd.de>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        <arch@FreeBSD.ORG>
Subject:   Re: -fno-builtin
Message-ID:  <Pine.BSF.4.33.0107091517020.17758-100000@beagle.fokus.gmd.de>
In-Reply-To: <Pine.BSF.4.21.0107092242340.87868-100000@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 9 Jul 2001, Bruce Evans wrote:

BE>On Mon, 9 Jul 2001, Harti Brandt wrote:
BE>
BE>> On Mon, 9 Jul 2001, Bruce Evans wrote:
BE>>
BE>> BE>I think it would work right except in broken code which "knows" that
BE>> BE>strlen isn't a macro, e.g.:
BE>> BE>
BE>> BE>	size_t (*p)(const char *s) = strlen;
BE>>
BE>> Why is that broken? My last copy of the ISO-C draft specifically states,
BE>> that strlen is a function. (Not that I intend to use that construct. Just
BE>> beeing curious).
BE>
BE>Does it really?  Almost any library function can be implemented as a
BE>(safe) macro (see section 7.1.4).  I can't find any exception for
BE>strlen.  This possibility is not completely transparent to applications.
BE>Code like the above should be aware of it.  Workarounds are easy in
BE>the above (just used "&strlen" or "(strlen)".  Section 7.1.4 documents

Well, hmmm, yes. The section on string.h states, that string.h contains
ONE type and ONE macro and several functions, but 7.1.4 allows all
functions to be macros. This means, that to take the address of ANY
library function you have to do either:

# undef func
	p = func;

or
	p = (func);

And
	p = &func;

does not help.

 BE>these.  Howver, I now remember a nasty example which
shows why BE>implementations should not do this:
BE>
BE>	len = strlen(
BE>#ifdef FOO
BE>	    "foo"
BE>#else
BE>	    "default"
BE>#endif
BE>	    );
BE>
BE>This causes errors like:
BE>
BE>z.c:11: warning: preprocessing directive not recognized within macro arg
BE>z.c:11: warning: preprocessing directive not recognized within macro arg
BE>z.c:11: warning: preprocessing directive not recognized within macro arg
BE>z.c: In function `main':
BE>z.c:6: undefined or invalid # directive
BE>z.c:8: undefined or invalid # directive
BE>z.c:10: undefined or invalid # directive
BE>
BE>I only learned of this example a weeks or two ago.  gcc-3.0 was reported
BE>to make a very fundamental function (printf?) a macro.

	len = (strlen)(
#ifdef FOO
	    "foo"
#else
	    "default"
#endif
	    );


should work then.

Thanks for the clarification,
harti
-- 
harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private
              brandt@fokus.gmd.de, harti@begemot.org


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.33.0107091517020.17758-100000>