[PATCH] staging: lustre: ldlm: use designated initializers

Kees Cook keescook at chromium.org
Tue Dec 20 19:46:35 UTC 2016


On Tue, Dec 20, 2016 at 11:07 AM, Dan Carpenter
<dan.carpenter at oracle.com> wrote:
> On Tue, Dec 20, 2016 at 02:57:17PM +0000, Hammond, John wrote:
>> "{ NULL }" is valid ISO C, but unfortunately "{}" is not.
>
> In the kernel we don't care.  We use lots of GCC extensions.

We depend on the compiler to do "incomplete zero-initialization" of
structures that are not mentioned in an initializer. The reason { NULL
} works is because the first field in the structure can take a NULL
value, and then the rest are zero-initialized by the compiler. { } is
the same thing, but doesn't use ordered initialization. If this style
is truly unacceptable to you, then { .somefield = NULL } can work, or
as you point out, if it's being initialized later, the static
initializer can be dropped entirely.

-Kees

-- 
Kees Cook
Nexus Security


More information about the devel mailing list