c++ - Include fight between data types -


sorry bad title, i'll try describe problem bit better..

i work real-time os. since have task test new feature , our main rtos not support yet, make prototype based on (until not used) rtos. new rtos brings own header files hosts many typedefs generate abbreviations ulong, bool, int, etc...

in our code-base there typedefs shall guarantee that, example, unsigned long 4 bytes. , according our styleguide new types shall used interface produce.
typedefs unfortunately named same ones new rtos (ulong, int, bool, ...).
build-breaking thing is, bool example once declared unsigned char , once int.
leads corruption of function-headers bool , other different types used.

my question is, how can make 1 of 2 "main" header , prefer it's typedefs on ones of other header-file?
, other ways see divide 2 headers?

since implement prototype on new rtos, changing our base-types seen less favored solution. appreciated , if need further clarification, let know!

edit:
ok, here's code further clarification:

rtos_typedefs.h

... typedef void void; typedef unsigned char bool; typedef int int; ... 


owncodebase_typedefs.h

... #define void void typedef int bool; typedef int int; 

now can see, int typedef same , causes no trouble.
void define collides void typedef in files , preprocessor produces following:

typedef void void; 

... generates compiler error.
bool typedef destroys function-headers since in 1 file rtos-version used , in other file typedef our code base used. compiler generates 2 different signatures , linker can't find definition 1 of them. -> error thrown

manually overriding typedefs preprocessor (ab)use option.

/* rename os version of 'bool' else */ #define bool osbool #include <osheader> #undef bool  /* when myheader.h included, bool still free typedef'd'. */ #include myheader.h 

the manual override prevent rtos overriding meaning of bool in application. typedef of bool instead typedef osbool , internal uses of bool replaced osbool.

repeat paradigm other primitive abbreviation wish override existing os-defined header type for.

note doing reverse possible. if have general header included in project's files, can #define macro bool there not reserved rtos after including headers. when run typedef bool char preprocessor first translate bool mybool, every use of in code files including header.

also see this question related ideas.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -