[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1538089739.226558.10.camel@acm.org>
Date: Thu, 27 Sep 2018 16:08:59 -0700
From: Bart Van Assche <bvanassche@....org>
To: Jason Gunthorpe <jgg@...pe.ca>,
Nick Desaulniers <ndesaulniers@...gle.com>
Cc: Nathan Chancellor <natechancellor@...il.com>, dledford@...hat.com,
linux-rdma@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] IB/mlx4: Avoid implicit enumerated type conversion
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.
Powered by blists - more mailing lists