tech-kern archive

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

Re: Some changes to autoconfiguration APIs



> Date: Sat, 07 Aug 2021 22:59:02 +0700
> From: Robert Elz <kre%munnari.OZ.AU@localhost>
> 
>     Date:        Wed, 4 Aug 2021 17:52:46 -0700
>     From:        Jason Thorpe <thorpej%me.com@localhost>
>     Message-ID:  <68FF8737-F347-4A7F-960B-9E4A6CA9EB59%me.com@localhost>
> 
>   | It addresses the concerns about compile-time type checking
>   | by using an anonymous structure constructed in-line
> 
> Is there something in the C definition of such things which guarantees
> that the un-init'd fields all get set to 0/NULL ?   Or is that just
> happening because of the "const" spread all over - which might be causing
> the compiler to allocate static storage, but which is not required of const?
> 
> Also, is there some way to distinguish an integer valued attribute which
> is explicitly set to 0 from one which isn't set at all (in which case we
> might want to default it to some other value) or do we only ever use
> attributes via various kinds of pointers (or perhaps never have any,
> anywhere ever, where 0 is a sensible value) ?

C11, Sec. 6.7.9 `Initialization', paragraph 19, p. 141:

  `The initialization shall occur in initializer list order, each
   initializer provided for a particular subobject overriding any
   previously listed initializer for the same subobject; all
   subobjects that are not initialized explicitly shall be initialized
   implicitly the same as objects that have static storage duration.'

And paragraph 10, p. 140:

  `....If an object that has static or thread storage duration is not
   initialized explicitly, then:

  `--- if it has pointer type, it is initialized to a null pointer;

  `--- if it has arithmetic tpye, it is initialized to (positive or
       unsigned) zero;

  `--- if it is an aggregate, every member is initialized
       (recursively) according to these rules, and any padding is
       initialized to zero bits;

  `--- if it is a union, the first named member is initialized
       (recursively) according to these rules, and any padding is
       initialized to zero bits.'

So pointers are nulled and integers are zero'd here -- and const is
not relevant, nor does the storage for these objects actually have
static duration; it's just that the anonymous struct objects with
designated initializers are initialized the same way as if they did
have static storage duration.


Home | Main Index | Thread Index | Old Index