This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: int a[0]={2};
- To: Klaus Niederkrueger <klaus at momo dot math dot rwth-aachen dot de>
- Subject: Re: int a[0]={2};
- From: Kip Macy <kip at lyris dot com>
- Date: Wed, 18 Aug 1999 10:33:22 -0700 (PDT)
- cc: gcc-bugs at gcc dot gnu dot org
Looking at the assembly for it, it is pretty obvious what is wrong:
more test.s
.file "test.c"
gcc2_compiled.:
.section .rodata
.LC0:
.string "%i\n"
.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
movl $5,-4(%ebp)
movl $2,-4(%ebp) # here it moves 2 into memory where 5 already is
addl $-8,%esp
movl -4(%ebp),%eax
pushl %eax
pushl $.LC0
call printf
addl $16,%esp
.L2:
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 2.95 19990728 (release)"
Why it does this is a question for the code-generation guys.
-Kip
On Wed, 18 Aug 1999, Klaus Niederkrueger wrote:
> Hi,
>
> I think I have found a small bug: Try this program on Linux
>
> egcs-2.91.60 Debian 2.1 (egcs-1.1.1 release)
>
> or
>
> gcc version 2.7.2.3
> .
> ------------------
>
>
> int main()
> {
> int b= 5;
> int a[0]={2};
>
> printf("%i\n",b);
> }
>
> ----------------------
>
>
> On my machine the computer gives "2" as result instead of "5" and even if I
> switch on "-Wall" I get no warning.
>
> If I use the following program
>
> --------------------
>
>
> int main()
> {
> int b= 5;
> int a[1]={2, 2};
>
> printf("%i\n",b);
> }
>
> ----------------------
>
> I get the warning message at compile-time
>
> test.c:4: warning: excess elements in array initializer after `a'
>
> and the result is "5" as it should be...
>
>
>
> I hope I am right and I don't waste your time.
>
> Greetings
>
> Klaus
>
>
>
>
>
>