GCC accepts dynamically-sized array in sizeof with -std=c89

Igor Bukanov igor@mir2.org
Wed Apr 16 14:15:00 GMT 2008


Consider the following program:

#include <stdio.h>

int f(int i)
{
    return sizeof(int [i ? 1 : -1]);
}

int main()
{
    printf("%d\n", f(0));
    return 0;
}

With GCC 4.3.0 it compiles without a warning even with -pedantic
-std=c89 even if the program uses dynamic array feature from C99:

~/s $ gcc -Wall -Wextra -std=c89 x.c
~/s $ ./a.out
-4

Is it a known bug?

Note that sizeof(int [i ? 1 : -1]) comes from the desire to write a
static_assert(condition) macro that should trigger a compile-time
error when condition is false.

Regards, Igor

P.S.I am not a subscriber to the list.



More information about the Gcc-help mailing list