tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] pointers to static functions inside a static table


From: Jay Foad
Subject: Re: [Tinycc-devel] pointers to static functions inside a static table
Date: Thu, 19 May 2011 11:44:36 +0100

>> >>       static struct s {
>> >>               void (*elem)();
>> >>       } t[] = {
>> >>               { func }        /* tcc requires these braces! */
>> >>       };
>>
>> The braces aren't required by C standards. That's why GCC *only* gives
>> a warning, not an error.
>
> Out of curiosity: why are they not strictly required? Because there is only
> one element in the struct?

No, it's not because there is only one element. You're allowed to
initialise all the elements of nested structs in storage layout order,
without putting in braces for all the sub-structs, e.g.:

struct {
        struct {
                int a, b;
        } c;
        struct {
                int d, e;
        } f;
} g = { 1, 2, 3, 4 };

See C99 6.7.8 "Initialization" paragraph 16 ff. for the rules (which I
find quite hard to read).

Jay.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]