This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
> I'd like the range check for switches on certain enums to be eliminated.
> In C, enums can actually have a value that's not in the enumeration list
> which defeats the optimisation: you can't assume every case is covered.
The situation is a bit different in C++: the legal values the compiler may
assume for an enum are those of the smallest signed or unsigned bitfield
that includes all the values (thus for two valid enums a and b, a|b
and a&b are always valid, and anything between the two values is valid).
That was a compromise between those who wanted really strong typing
and those that wanted to make sure that traditional C usages would
continue work.
> However, there are two approaches to eliminating the bounds check:
>
> - __builtin_assume (x < 6);
>
> - __attribute__ ((bounded)) enum Foo { A, B, C} foo;
In C++, the compiler may assume that a Foo is 0, 1, 2, or 3 (so there is
one extra value).
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |