Em 02-05-2012 21:42, Andy Walls escreveu: > On Wed, 2012-05-02 at 19:17 -0300, Mauro Carvalho Chehab wrote: > >> We can speed-up the conversions, with something like: >> >> enum foo { >> BAR >> }; >> >> if (sizeof(foo) != sizeof(u32)) >> call_compat_logic(). >> >> I suspect that sizeof() won't work inside a macro. > > sizeof() is evaluated at compile time, after preprocessing. > It should work inside of a macro. I tried to compile this small piece of code: enum foo { BAR }; #if sizeof(foo) != sizeof(int) void main(void) { printf("different sizes\n"); } #else void main(void) { printf("same size\n"); } #endif It gives an error: /tmp/foo.c:2:11: error: missing binary operator before token "(" So, either this doesn't work, because sizeof() is evaluated too late, or some trick is needed. Weird enough, cpp generates the error, but the expression is well-evaluated: $ cpp /tmp/foo.c # 1 "/tmp/foo.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "/tmp/foo.c" /tmp/foo.c:2:11: error: missing binary operator before token "(" enum foo { BAR }; void main(void) { printf("same size\n"); } Changing from "sizeof(foo)" to "sizeof foo" also doesn't solve: /tmp/foo.c:2:12: error: missing binary operator before token "foo" Maybe some trick is needed for it to work. > See the ARRAY_SIZE() macro in include/linux/kernel.h for a well tested > example. ARRAY_SIZE() doesn't have an #if on it. Regards, Mauro -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html