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 to either uint8_t or uint16_t. With macros you >> don't need to cast since they are typeless.
Defines without type specifier are of type "int", not typeless. (e.g.: --- [kaspar@localhost tmp]$ cat test.c #include <stdio.h> int main(){ printf("0x%8x\n", ~0); } [kaspar@localhost tmp]$ gcc test.c -o test [kaspar@localhost tmp]$ ./test 0xffffffff [kaspar@localhost tmp]$ --- enums are mostly "int" but may be any type that fit every member of the enum. So they behave the same when used as constants. That means when writing to bitfields, the assignment has to be made either through a pointer of the right size on the left hand or by using a mask. When stored in a struct, with defines you'd have to specify the type of a variable holding that flag. You can do the same with enums, as Pekka pointed out. Kaspar _______________________________________________ devel mailing list devel@riot-os.org https://lists.riot-os.org/mailman/listinfo/devel