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

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

 



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.

[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