This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __builtin_string_constant_p
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 10 Aug 2004 22:56:14 +0000 (UTC)
- Subject: Re: __builtin_string_constant_p
- References: <87brhiwsbc.fsf@deneb.enyo.de>
On Wed, 11 Aug 2004, Florian Weimer wrote:
> For some routines that should only accept string literals, it would be
> nice to have a __builtin_string_constant_p built-in. For example,
Meaning what exactly, for such cases as
foo(complicated_expression ? "bar" : non_string)
where complicated_expression might or might not be optimised to 1?
Or indeed
inline int foo(const char *p)
{
return __builtin_string_constant_p(p);
}
inline int bar(const char *p)
{
return foo(p);
}
- is bar("baz") required to be 1? What of bar(((("baz"))))?
(I've just written 1000 lines of formal models of constant expression
rules for C90, C99 and GNU C, and the specification of
__builtin_constant_p has the unsatisfactory property of depending on
whether the compiler folds it at parse time (as e.g. in static
initializers) or waits to see if it can be optimized later (e.g. constant
parameters to inline functions). In general a language specification that
depends on what the compiler of the day can optimize is not ideal, and in
most regards the formal models avoid such dependency.)
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)