|
|
|
|
|
by peterdn
3493 days ago
|
|
In some compilers due to C99 variable length arrays [1], your macro compiles happily if passed a value that is not a compile-time constant. For example, this compiles but segfaults at runtime (GCC 4.9.2): int main(int argc, char * argv[]) {
return (sizeof(char[(argc) ? -1 : 1]) - 1);
}
[1] https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html |
|
The negative-length array trick is used in the Linux kernel source code [1]. I expect it's compiled with -Wvla though.
[1] https://github.com/torvalds/linux/blob/v4.5/arch/x86/boot/bo...