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

* Re: GCC accepts dynamically-sized array in sizeof with -std=c89
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Jim Wilson @ 2008-04-18 18:27 UTC (permalink / raw)
  To: Igor Bukanov; +Cc: gcc-help

Igor Bukanov wrote:
> 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:

It works for me.

localhost$ ./xgcc -B./ -std=c89 tmp2.c
localhost$ ./xgcc -B./ -std=c89 -pedantic tmp2.c
tmp2.c: In function ‘f’:
tmp2.c:5: warning: ISO C90 forbids variable length array
localhost$ ./xgcc -B./ -v
Reading specs from ./specs
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --enable-languages=c
Thread model: posix
gcc version 4.3.1 20080411 (prerelease) [gcc-4_3-branch revision 134209] 
(GCC)

Adding -pedantic does generate the warning.  Perhaps you expected a 
warning without -pedantic?  If you read the docs carefully, you will see 
that -std=c89 enables all features of that standard, but does not 
disable GNU extensions to that standard.  You need -pedantic for that.

Jim

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

* Re: GCC accepts dynamically-sized array in sizeof with -std=c89
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Igor Bukanov @ 2008-04-19  4:54 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-help

On 18/04/2008, Jim Wilson <wilson@tuliptree.org> wrote:
>  Adding -pedantic does generate the warning.  Perhaps you expected a warning
> without -pedantic?  If you read the docs carefully, you will see that
> -std=c89 enables all features of that standard, but does not disable GNU
> extensions to that standard.  You need -pedantic for that.

You are right, I have misted -pedantic and with -pedantic-errors the
example does generated the error.

Regards, Igor

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

* Re: GCC accepts dynamically-sized array in sizeof with -std=c89
  2008-04-19  4:54   ` Igor Bukanov
@ 2008-04-19  7:03     ` Igor Bukanov
  2008-04-19  9:33     ` Igor Bukanov
  1 sibling, 0 replies; 5+ messages in thread
From: Igor Bukanov @ 2008-04-19  7:03 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-help

On 18/04/2008, Jim Wilson <wilson@tuliptree.org> wrote:
>  Adding -pedantic does generate the warning.  Perhaps you expected a warning
> without -pedantic?  If you read the docs carefully, you will see that
> -std=c89 enables all features of that standard, but does not disable GNU
> extensions to that standard.  You need -pedantic for that.

You are right, I have misted -pedantic and with -pedantic-errors the
example does generated the error.

Regards, Igor

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

* Re: GCC accepts dynamically-sized array in sizeof with -std=c89
  2008-04-19  4:54   ` Igor Bukanov
  2008-04-19  7:03     ` Igor Bukanov
@ 2008-04-19  9:33     ` Igor Bukanov
  1 sibling, 0 replies; 5+ messages in thread
From: Igor Bukanov @ 2008-04-19  9:33 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-help

On 18/04/2008, Jim Wilson <wilson@tuliptree.org> wrote:
>  Adding -pedantic does generate the warning.  Perhaps you expected a warning
> without -pedantic?  If you read the docs carefully, you will see that
> -std=c89 enables all features of that standard, but does not disable GNU
> extensions to that standard.  You need -pedantic for that.

You are right, I have misted -pedantic and with -pedantic-errors the
example does generated the error.

Regards, Igor

^ 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).