lkml.org 
[lkml]   [2018]   [Sep]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] IB/mlx4: Avoid implicit enumerated type conversion
From
Date
On Thu, 2018-09-27 at 16:58 -0600, Jason Gunthorpe wrote:
> Anyhow, the standard is hard to read in this area, but reality is
> this:
>
> #include <stdio.h>
>
> enum a
> {
> A1 = 1,
> A2 = 1ULL<<40,
> };
>
> int main(int argc, const char *argv[])
> {
> printf("%zu\n", sizeof(enum a));
> return 0;
> }
>
> $ gcc -Wall -std=c11 test.c && ./a.out
> 8
>
> I forget if this a common compiler extension, unclear standard, or was
> formally revised in C11 or what, but it is the real world the Linux
> kernel lives in.
>
> It is even more confusing if you wonder what types A1 and A2 are!

What's unfortunate is that gcc and sparse have different opinions about how
to compile the above code. Even if gcc supports enumeration constants that
exceed what fits in an int, sparse does not AFAIK.

Bart.

\
 
 \ /
  Last update: 2018-09-28 01:09    [W:0.074 / U:0.880 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site