[Mesa-dev] [PATCH 2/4] st/mesa: use enum types instead of int/unsigned (v3)

Erik Faye-Lund kusmabite at gmail.com
Wed Nov 8 17:08:15 UTC 2017


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 {
   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.


More information about the mesa-dev mailing list