Re: "Using plain integer as NULL pointer" false positive for zero struct initializer

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

 



On Wed, Jan 9, 2019 at 11:01 AM Ramsay Jones
<ramsay@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Ahem, so yes, both gcc and clang allow this (I just tested it), but
> my reading of the C99 standard lead me to believe that this is not
> valid C. (Not that it really matters).

Interesting. Looking at the kernel, we actually have a lot of them, ie

    [torvalds@i7 linux]$ git grep 'struct.*= {[:space:]*}' | wc
       1105    6766   81616

although admittedly we also have a fair amount of the { 0 } kind:

    [torvalds@i7 linux]$ git grep 'struct.*= {[:space:]*0[:space:]*}' | wc
        616    3722   50034

and I didn't realize that the empty one might not even be standard.

We used to (long long) ago have code like this:

 /*
  * gcc versions before ~2.95 have a nasty bug with empty initializers.
  */
 #if (__GNUC__ > 2)
   typedef struct { } spinlock_t;
   #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
 #else
   typedef struct { int gcc_is_buggy; } spinlock_t;
   #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
 #endif

but that was iirc not strictly about the empty initializers, it was
also about the structure itself being empty, and that confusing gcc.
But my memory might be dodgy on this.

(And in fact, that "before ~2.95" was apparently "egcs-1.1". So we're
talking truly old versions of gcc, this is pre-2000).

                Linus



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux