Trouble compiling with binary constants

Topics for the Eclipse Environment
Post Reply
scootertrash
Posts: 1
Joined: Thu Jan 03, 2013 1:01 pm

Trouble compiling with binary constants

Post by scootertrash »

I'm trying to compile the following in Eclipse (NNDK 2.4 RC2) targeted to a MOD5234:

const UINT8 MapFansToFanSets[] =
{
0b00000000, // 0 fans
0b00000001, // 1 fan
0b00000011, // 2 fans
0b00000111, // 3 fans
0b00001111, // 4 fans
0b00011111, // 5 fans
0b00111111, // 6 fans
0b01111111, // 7 fans
0b11111111 // 8 fans
};

(NB: 'UINT8' is #defined as 'unsigned char'...)

And I get the following errors:

..\env_fans.cpp:22:4: error: invalid suffix "b00000000" on integer constant
..\env_fans.cpp:23:4: error: invalid suffix "b00000001" on integer constant
..\env_fans.cpp:24:4: error: invalid suffix "b00000011" on integer constant
..\env_fans.cpp:25:4: error: invalid suffix "b00000111" on integer constant
..\env_fans.cpp:26:4: error: invalid suffix "b00001111" on integer constant
..\env_fans.cpp:27:4: error: invalid suffix "b00011111" on integer constant
..\env_fans.cpp:28:4: error: invalid suffix "b00111111" on integer constant
..\env_fans.cpp:29:4: error: invalid suffix "b01111111" on integer constant
..\env_fans.cpp:30:4: error: invalid suffix "b11111111" on integer constant

I Googled "gcc binary constants" and it looks like I did it right.

Any suggestions?

Thanx!

Scott
greengene
Posts: 164
Joined: Wed May 14, 2008 11:20 am
Location: Lakeside, CA

Re: Trouble compiling with binary constants

Post by greengene »

the binary format is available only starting from gcc 4.3.
NNDK 2.4rc2 is using gcc 4.2.1.
NNDK 2.6 is still using 4.2.1.
http://gcc.gnu.org/gcc-4.3/changes.html

so you might just want to do your assignments in hex, e.g.,
const UINT8 MapFansToFanSets[] =
{
0x00, // 0 fans
0x01, // 1 fan
0x03, // 2 fans
0x07, // 3 fans
0x0f, // 4 fans
0x1f, // 5 fans
0x3f, // 6 fans
0x7f, // 7 fans
0xff // 8 fans
};
Last edited by greengene on Fri Jan 04, 2013 9:20 am, edited 1 time in total.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Trouble compiling with binary constants

Post by tod »

If you really want to use binary constants take a look at the the BOOST_BINARY macro. I've never used it, but it looks like it should do the trick.
Post Reply