[Mesa-dev] [PATCH 2/4] st/mesa: use enum types instead of int/unsigned (v3)
Ian Romanick
idr at freedesktop.org
Thu Nov 9 01:32:52 UTC 2017
On 11/08/2017 09:08 AM, Erik Faye-Lund wrote:
> On Wed, Nov 8, 2017 at 1:07 AM, Brian Paul <brianp at vmware.com> wrote:
>> Use the proper enum types for various variables. Makes life in gdb
>> a little nicer. Note that the size of enum bitfields must be one
>> larger so the high bit is always zero (for MSVC).
>
> You *could* also do something like this on MSVC to get unsigned enum
> values, thus not needing the extra bit:
>
> ---8<---
> #include <stdio.h>
>
> #ifdef _MSC_VER
> #define FORCE_UNSIGNED : unsigned
> #else
> #define FORCE_UNSIGNED
> #endif
>
> enum Foo FORCE_UNSIGNED {
Looking at
https://stackoverflow.com/questions/837319/packing-enums-using-the-msvc-compiler,
I think some variation of this may solve the attribute((packed)) problem
too. See my other e-mail. Basically an enum can be forced to be a type
of a particular size using this technique. Maybe a ENUM_8BITS that is
": unsigned char" on MSVC and "__attribute__((__packed__))" on GCC?
> FOO_A = 1,
> FOO_B = 255
> };
>
> struct Bar {
> Foo foo : 8;
> };
>
> int main()
> {
> Bar foo;
> foo.foo = FOO_B;
> printf("%d\n", foo.foo);
> return 0;
> }
> ---8<---
>
> This outputs 255 on MSVC.
>
> It's not beautiful, though.
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list