How to identify the C compiler being used

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[I hate to ask questions that must have been answered somewhere in the docs, but i searched the manuals without success...]

In order to easily simulate parts of my current project, i wrote a small simulator for my actual hardware in Dev-Cpp on the PC (Windows) to test my state machine code. The module containing the state machine is written in a portable way without any knowledge of the underlying hardware. Now, how can i detect the platform i'm compiling this module on? I mean there must be some definition of __AVRGCC__ or such, but so far i couldn't find any documentation about such defined words in the avr-gcc environment.

Can you tell me what definition to check for to tell that the module should be compiled for an AVR? And, could you post a reference to the relevant docs you found that info?

Thanks in advance,

-- Thilo

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

__GNUC__
__CODEVISIONAVR__
__IAR_SYSTEMS_ICC__
__IMAGECRAFT__
__ROWLEY

You need to also detect the CPU model etc. Unfortunately this can get a little bloated: e.g.

#if defined(__AVR_ATxmega128A1__) || defined(_CHIP_ATXMEGA128A1_)

because all Compilers use a different system to identify the model.

But you should find the predefined macros advertised/hidden in the Compiler docs.

David.

Last Edited: Fri. Nov 27, 2009 - 09:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A lot of ways.

I have just used

#ifdef AVR

or

#ifdef WIN32

or similar. There is a command to see what preprocessor macros are defined. The AVR and WIN32 may be in the form of __AVR__ or __WIN32__, I don't remember any more.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks to all for the answers, i gues Jepael's hint for testing "AVR" ist the one i was for. I can't use __GNUC__ since there are GNU C Compilers for Windows as well, and i need to determine the general hardware platform. I guess i could also just test if __AVR_ARCH__ is defined...

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At the top of the link I posted (manual) it shows that avr-gcc defines AVR, __AVR, and __AVR__

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah-ha. You did want to distinguish platforms and not just the Compiler.

#if defined(__GNUC__) && defined(AVR)

Likewise you have to test both Compiler and Target for IAR etc...

Not all AVR Compilers predefine 'AVR'. It is safer to use the __NAMES__ because they are more likely to reflect the particular Compiler.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, i neglected to mention that i'm using avr-gcc/WinAVR for the 'real' stuff. But in order to distinguish the different platforms for a build run, it's simply not enough to check for GNUC, when your compiler on the PC side is also a GCC variant (and i mentioned Dev-Cpp in the base note). Therefore i really was looking for a way to distinguish the platform, not the compiler. And this has been addressed for avr-gcc/WinAVR pretty fine with the AVR/__AVR__ definitions.

Again thanks to all for the very useful comments!

-- Thilo

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could always do it yourself, e.g.

... -D__PLATFORM__=avr-gcc_on windows95 ...

"SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then." -- John Woods