3 ms·
I use that macro frequently but warily. The fact that it only works with static arrays and (AFAIK) the compiler won't warn you if you accidentally use it on dyn
by AceJohnny2 12y ago
I use that macro frequently but warily. The fact that it only works with static arrays and (AFAIK) the compiler won't warn you if you accidentally use it on dynamic arrays/pointers/array parameters is a big risk.
Come to think of it, I'm afraid I'm leaving a time bomb for the next inexperienced maintainer who doesn't know the limitations.
- RustyRussell 12y agoSee the one I wrote for the Linux kernel; it will error at build time on a non-array (using tyoeof). Even better, grab it from CCAN: http://ccodearchive.net/info/array_size.html http://ccodearchive.net/info/array_size.html Cheers, Rusty.
- AceJohnny2 12y agoThanks! I see you use __builtin_types_compatible_p, which looks very useful but also appears to be a GCC-specific.