#define to tell I'm compiling in xTIMEcomposer/xcc

Technical questions regarding the XTC tools and programming with XMOS.
mattbudd
New User
Posts: 3
Joined: Fri Mar 14, 2014 10:11 pm

#define to tell I'm compiling in xTIMEcomposer/xcc

Post by mattbudd »

Hello all,

I'm trying to build some common code (across many compilers), and I want to conditionally change that code depending on what compiler is building it (i.e. things like certain data types, includes, etc.). I have the following flags already:

- for GCC builds, I can check if __GNUC__ is defined
- for IAR builds, I can check if __ICCARM__ is defined
- for Microsfot Visual C builds, I can check if _MSC_VER is defined

For xTIMEcomposer/xcc builds, what #define can I check?


srinie
XCore Addict
Posts: 158
Joined: Thu Mar 20, 2014 8:04 am

Post by srinie »

Did you try this?

#ifdef __XC__
..
..
#endif
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You should not normally test which compiler is used; this
just leads to an unmaintainable mess, and breaks for all
compilers and compiler versions you haven't tested (including
future versions). Instead, you should test for the exact
feature you rely on.

That said, you probably want __clang__ or XCC_VERSION_MAJOR.
Try

Code: Select all

xcc -E -dM -xc /dev/null
(or create an empty file and use that, if your OS/shell
is limited).
mattbudd
New User
Posts: 3
Joined: Fri Mar 14, 2014 10:11 pm

Post by mattbudd »

Thanks for the help, XCC_VERSION_MAJOR is what I am looking for. Much appreciated.