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 09/01/2019 19:15, Linus Torvalds wrote:
> 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.
> 

OK, so I spent some time reading the C99 and C11 standards and
I _still_ can't see how this could be valid C!

So, I beat on gcc some more:

$ cat -n junk.c
     1	#include <stdio.h>
     2	
     3	int main (int argc, char *argv[])
     4	{
     5		struct { char *f; int i; } fred = {};
     6		printf("fred.f %p (%s), fred.i %d\n", fred.f, fred.f, fred.i);
     7		return 0;	
     8	}
$ gcc -std=c99 -pedantic -Wall -Wextra -o junk junk.cjunk.c: In function ‘main’:
junk.c:5:36: warning: ISO C forbids empty initializer braces [-Wpedantic]
  struct { char *f; int i; } fred = {};
                                    ^
junk.c:3:15: warning: unused parameter ‘argc’ [-Wunused-parameter]
 int main (int argc, char *argv[])
               ^~~~
junk.c:3:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
 int main (int argc, char *argv[])
                           ^~~~
$ ./junk
fred.f (nil) ((null)), fred.i 0
$ 

... and finally got it to admit that {} is not ISO C (with -pedantic).

[I was starting to doubt myself! ;-) ]

ATB,
Ramsay Jones





[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