On 11/25/2013 02:15 PM, Laszlo Ersek wrote:

>>>>>> +    char s[] = "XXXX";
>>>>>
>>>>> char s[5];
>>>>>
>>>>> Initializing it is a waste of time.

And storage - the string literal occupies space in the binary image.

>>> Then do something like
>>>
>>>   char s[sizeof("XXXX")];

Not to mention we already have at least one example of that idiom:

disas/cris.c:  char temp[sizeof (".d [$r13=$r12-2147483648],$r10") * 2];

> (Admittedly, EXAMPLE 4 in 6.7.5.2 Array declarators, p10, is informative
> (not normative), and 6.7.5.2 Array declarators, p2, speaks about an
> "identifier". We don't have an identifier for "XXXX", but I think we can
> still derive that static storage duration implies non-variable length
> for the array that holds the string.)

Yes, use of char s[sizeof("")] is a fairly common idiom in C
programming, when you want to size the array large enough for it's
worst-case contents without actually wasting initialization/storage to
those contents.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to