Re: [riot-devel] enums vs. macros

2015-05-13 Thread Kaspar Schleiser
Hey, On 05/13/15 08:12, Oleg Hahm wrote: >> Because flags have a width in memory that is in most cases smaller than >> sizeof(enum) (most bit fields I know of are 16 bits max, on most of our >> newer platforms, sizeof(enum) is however 32 bits). This results in every >> assignment needed to be cast

Re: [riot-devel] enums vs. macros

2015-05-13 Thread Joakim Gebart
gcc's -fshort-enums might do what you describe: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html: -fshort-enums Allocate to an enum type only as many bytes as it needs for the declared range of possible values. Specifically, the enum type is equivalent to the smallest integer type that ha

Re: [riot-devel] enums vs. macros

2015-05-12 Thread Oleg Hahm
Hi! Another possibility would be to use packed enums but enforce/check their size at build time with something like Rene proposed here: https://github.com/RIOT-OS/RIOT/pull/1286 Cheers, Oleg Am Wed, May 13, 2015 at 09:21:14AM +0300 schrieb Pekka Nikander: > A silly question/suggestion: > > Woul

Re: [riot-devel] enums vs. macros

2015-05-12 Thread Pekka Nikander
A silly question/suggestion: Wouldn't it make sense to use sized integer types in the struct, but a separate enum to define the values? IIRC, enum's in C are simply named integer constants. C is also very permitting in storing values into smaller integer types. For C++, of course, the situat

[riot-devel] enums vs. macros

2015-05-12 Thread Oleg Hahm
Dear replying IoTlers, some time ago I had a discussion with Martine on GitHub about the usage of enums for flags [1]. Martine convinced me that seems to be wise to prefer macros over enums here, to avoid alignment issues. However, it feels somehow wrong not to use enums for this purpose (it's eas