Compiler Depenedent Error with typedef

4.8k views Asked by At

I am trying to compile my project with different compilers. i have a stable compiled version of the project compiling without any error with the ARM 4.41 compiler. I want to compiler the exactly same source code with the ARM 5 compiler and the Win64 compiler. How ever without any change in the source code, just by switching the compiler from ARM 4.41 to ARM 5 && ARM 4.41 to Win64 i am getting the following error with the typedef's.

I am not able to figure it out, why does it behaves so..?

Header file with typedef's - a_stdtypes.h

#define _STD_TYPE_H
typedef unsigned char  bool; // Error #84: invalid combination of type specifiers
typedef unsigned char  bit8;
typedef unsigned short bit16;
typedef unsigned long  bit32;
2

There are 2 answers

2
Angew is no longer proud of SO On

This isn't legal C++ code. bool is a reserved keyword of the language - a type. You cannot redefine its meaning. It would be legal C code, though.

2
SHR On

I guess it was wrote because someone want to define bool for C, then someone else want to use it from C++.

a neater solution is to use cplusplus macro, like this:

#ifndef __cplusplus
typedef unsigned char  bool;
#endif
typedef unsigned char  bit8;
typedef unsigned short bit16;
typedef unsigned long  bit32;