Page 1 of 1

Trouble compiling with binary constants

Posted: Thu Jan 03, 2013 1:06 pm
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

Re: Trouble compiling with binary constants

Posted: Fri Jan 04, 2013 9:13 am
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
};

Re: Trouble compiling with binary constants

Posted: Mon Jan 07, 2013 9:01 am
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.