[cfe-dev] _Generic constant string as controlling expression
Zhihao Yuan
zy at miator.net
Mon Dec 9 12:26:15 PST 2013
On Mon, Dec 9, 2013 at 3:17 AM, Richard Smith <richard at metafoo.co.uk> wrote:
>> Since this clause has no mention for _Generic, shouldn't the type of
>> "hello"
>> be converted from char[6] to char * when it's used as a controlling
>> expression ?
>> Or am I missing something ?
>
>
> Yes, I think it should -- this looks like a bug. Please file a bug report!
I don't think so. It looks more like an overlook to me. CC'ed Clark (the
author of _Generic).
At a first glance, performing an array-to-pointer conversion make things
easier, but imagine something like this:
#define F(e) _Generic(e, char *: sizeof(e))
So what, sizeof a pointer is the array length? This leads very obscure
programs. Please don't. In unevalued context (stealing C++ term here),
no convert should be performed.
Here is an solution (no matter this is a bug in which side):
http://stackoverflow.com/questions/18857056/c11-generic-how-to-deal-with-string-literals
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
More information about the cfe-dev
mailing list