Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



See 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

Cheers, Rusty.


Thanks!

I see you use __builtin_types_compatible_p, which looks very useful but also appears to be a GCC-specific.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: