public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC accepts dynamically-sized array in sizeof with -std=c89
@ 2008-04-16 14:15 Igor Bukanov
  2008-04-18 18:27 ` Jim Wilson
  0 siblings, 1 reply; 5+ messages in thread
From: Igor Bukanov @ 2008-04-16 14:15 UTC (permalink / raw)
  To: gcc-help

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-04-19  1:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-16 14:15 GCC accepts dynamically-sized array in sizeof with -std=c89 Igor Bukanov
2008-04-18 18:27 ` Jim Wilson
2008-04-19  4:54   ` Igor Bukanov
2008-04-19  7:03     ` Igor Bukanov
2008-04-19  9:33     ` Igor Bukanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).