tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: alloca again
On Mon, Oct 03, 2022 at 02:20:20PM -0400, Mouse wrote:
> >>> #if defined(_NETBSD_SOURCE)
> >>> #if defined(alloca) && (alloca == __builtin_alloca) && \
> >> [...]
> > _NETBSD_SOURCE and __builtin_alloca are each in reserved-for-any-use
> > namespace, so there are no grounds for citing the standard as basis
> > for any behaviour whatsoever from that.
>
> I think I overstated the case. Those two _are_ reserved, but I think
> testing them in the preprocessor like that does not produce undefined
> behaviour. (Quotes below.)
>
> I think it would be conformant for __builtin_alloca to expand to, for
> example, the four tokens & < % 14. Presumably this would be done only
> when the compiler in question accepts that, but even then I think there
> is no requirement that compiler accept that as part of a *preprocessor*
> expression.
>
> Of course, this is not to say that the test quoted is a bad thing, only
> that it is nonportable - but nonportability is not necessarily a bad
> thing in implementation-specific places (such as system headers). It
> *does*, however, mean that citing the standard as basis for expecting
> any particular behaviour is unjustified.
I think it is reasonably plausible to do the following:
- provide a "weak" macro definition of alloca -> __builtin_alloca
(such that another #define implicitly removes it);
- handle equality tests of identifiers beginning with __builtin
with strcmp.
The former is not compliant, but unlikely to cause trouble unless
someone used the name "alloca" expecting it to be an ordinary
identifier and not a libc element, and without including <stdlib.h>;
and in 1993 when this thing was inserted the likely reaction to such
trouble would be "don't do that".
The latter seems to be perfectly legitimate since it's equivalent to
predefining a bunch of things in the reserved namespace to magic token
sequences.
I can't remember exactly how builtins worked in gcc2 but I have a
vague recollection it may have been something like this.
Also remember that in 1993 there realistically wasn't another
compiler.
If we still cared about gcc2 it might be better to put that part of
the test first in the expression so the rest isn't evaluated in other
compilers, but we don't.
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index