LWN.net Logo

Rusty's obfuscated (but serviceable) macro gets an explanation

Rusty's obfuscated (but serviceable) macro gets an explanation

Posted Mar 15, 2007 16:41 UTC (Thu) by pr1268 (subscriber, #24648)
Parent article: Quotes of the week

Hehe, reading further down the thread, someone asked for some documentation explaining how this macro works.

Rusty obliged the request with:

+/* GCC is awesome. */
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])      \
  + sizeof(typeof(int[1 - 2*!!__builtin_types_compatible_p(typeof(arr), \
    typeof(&arr[0]))]))*0)

That explains it all so clearly! ;-)


(Log in to post comments)

Rusty's obfuscated (but serviceable) macro gets an explanation

Posted Mar 16, 2007 10:32 UTC (Fri) by nix (subscriber, #2304) [Link]

He learned his commenting style from JWZ, I'd say :)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds