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

Re: [microblaze-uclinux] c++ non-constant initializers



Hei!

Are you sure that you are compiling C++-Code? The sample code provided 
seems to confirm to usual C; thus compiling it with gcc on a x86 results 
in:

~# gcc test.c
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[0]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[1]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[2]')
test.c:4: error: initializer element is not constant
test.c:4: error: (near initialization for 'seq2[3]')

Regards,
Nicolas

On Wednesday, 09/10/08 at 17:37 (+0200), Torsten Schmutzler wrote:
> From: Torsten Schmutzler <s6757418@xxxxxxxxxxxxxxxxx>
> To: microblaze-uclinux@xxxxxxxxxxxxxx
> Date: Wed, 10 Sep 2008 17:37:28 +0200
> Subject: [microblaze-uclinux] c++ non-constant initializers
> User-Agent: Thunderbird 2.0.0.16 (X11/20080724)
> 
> Hi,
>
> I'm trying to port a c++ Framework to microblaze, but there are problems  
> with the generated binaries.
>
> Here is some code to demonstrate the problem:
>
> #include <stdio.h>
>
> const unsigned char seq[] = { 0x54, 0x45, 0x53, 0x54 };  // TEST
> const unsigned char seq2[] = { seq[0], seq[1], seq[2], seq[3] };
>
> int main() {
>     printf("%x %x %x %x\n", seq[0], seq[1], seq[2], seq[3]);
>     printf("%x %x %x %x\n", seq2[0], seq2[1], seq2[2], seq2[3]);
>     return 0;
> }
>
> Compiling and running on a pc gives:
> 54 45 53 54
> 54 45 53 54
>
> builing for mb results in:
> 54 45 53 54
> 0 0 0 0
>
> So it seems the initializers are not run. The code above is legal C++, so:
> - can somebody reproduce this behavior?
> - Are there compiler switches to make the code work?
> - Or is this just a bug in microblaze-uclinux-g++?
>
> Thanks
> Torsten
>

-- 
gpg public key: ID 0xACBC3B35, jabber: nicolas@xxxxxxxxx
 -- frykten for herren er opphav til kunnskap --

Attachment: pgpVHAxPTqkIn.pgp
Description: PGP signature