[cfe-dev] Nasty problem in sizeof evaluation?

Abramo Bagnara abramo.bagnara at gmail.com
Sun Sep 26 00:44:09 PDT 2010


$ cat p.c
#define HUGE (1LL<<61)
typedef char a[HUGE];
typedef char b[(long long)sizeof(a)-1];

$ clang -m64 p.c
p.c:3:16: error: array size is negative
typedef char b[(long long)sizeof(a)-1];
               ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.

I believe this is due to the fact that type size is evaluated in bits
unit with 64 bits of precision and then it is divided by 8.

This lead to the observed problem.



More information about the cfe-dev mailing list