Safer determination of static array size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A lot of programs contain a definition like the following one:

#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))

If this is applied to a pointer instead of an array, this still compiles and the result is wrong.

I wonder if there is a kludge we can apply to make this fail to compile. Warning about the sizeof(a) / sizeof(*a) construct when a is not of array type might make sense as well.

--
Florian Weimer / Red Hat Product Security Team




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux