Reply by aekalman April 22, 20042004-04-22
Re:

> i'm using defines and ifs/elses for compiling
with different
compilers 
> and to automatize this i'm looking for
compiler (or preprocessor) 
> dependent defines .
> Does someone has  a list of macros/functions or something else
which is 
> only availible with one compiler/preprocessor?

Just look in Salvo's salvo.h ....

Andrew Kalman   aek ... at ... pumpkininc ... dot ... com


Beginning Microcontrollers with the MSP430

Reply by Rolf F. April 22, 20042004-04-22
Hi,

ok, now i'm using this version (for IAR 1x and mspgcc):

// compiler autodetection
#   ifdef COMPILER_OK
#      undef COMPILER_OK
#   endif
#   ifdef __IAR_SYSTEMS_ICC__
/* This is an IAR Compiler. */
#      if (((__TID__ >> 8) & 0x7f) == 43)
/* This is the IAR MSP430 compiler. */
#         define IAR
#         if (__VER__ < 200)
/* V1.xx of the compiler. */
#            define IARV1
#            define COMPILER_OK
#         else
#            if (__VER__ < 300)
/* V2.xx of the compiler. */
#               define IARV2
#            else
#               if (__VER__ < 400)
/* V3.xx of the compiler. */
#                  define IARV3
#               endif
#            endif
#         endif
#      endif
#      if (((__TID__ >> 8) & 0x7f) == 45)
/* This is the IAR CR16C compiler. */
#         error "No MSP430 compiler."
#      else
#         if (((__TID__ >> 8) & 0x7f) == 85)
/* This is the IAR V850 compiler. */
#            error "No MSP430 compiler."
#         else
/* Unknown IAR compiler. */
#         endif
#      endif
/* not IAR: */
#   else
#      if defined(MSP430) && defined(__MSP430__) &&
defined(__GNUC__)
/* MSPGCC */
#         define MSPGCC
#         define COMPILER_OK
#
/* MCU check */
// #ifndef __MSP430_W427__
// #  error "Wrong MCU."
// #endif
#
/* not IAR, not MSPGCC: */
#      else
#         ifdef __AQCOMPILER__
#
#         endif
#      endif /* NOT MSPGCC */
#   endif /* NOT IAR */
/* final compiler check */
#   ifndef COMPILER_OK
#      error "Unknown or not supported compiler/preprocessor."
#   endif
/* End compiler autodetection */


Rolf


Anders Lindgren schrieb:

>Hi!
>
>  
>
>>the actual version is:
>>#   else
>>#      if defined(MSP430) && defined(__MSP430__)
>>/* MSPGCC */
>>#         define MSPGCC
>>#         define COMPILER_OK
>>    
>>
>
>May I suggest that you add "defined(__GNUC__)" to this test as
well?
>(This symbol is defined by all gcc variants, as far as I know.)
>
>Both the symbol MSP430 and __MSP430__ are generic and may very well be
>defined by other (present or future) compilers, in which case you will
>mistake them for GCC.
>
>    -- Anders
>  
>



Reply by rotamat2000 April 22, 20042004-04-22
You are right, I found this faq right now: 
http://mspgcc.sourceforge.net/faq/x55.html

Thanks,

Patrik

--- In msp430@msp4..., Anders Lindgren <andersl@i...> wrote:
> 
> Hi!
> 
> > the actual version is:
> > #   else
> > #      if defined(MSP430) && defined(__MSP430__)
> > /* MSPGCC */
> > #         define MSPGCC
> > #         define COMPILER_OK
> 
> May I suggest that you add "defined(__GNUC__)" to this test as
well?
> (This symbol is defined by all gcc variants, as far as I know.)
> 
> Both the symbol MSP430 and __MSP430__ are generic and may very well 
be
> defined by other (present or future) compilers, in
which case you 
will
> mistake them for GCC.
> 
>     -- Anders
> -- 
> Disclaimer: Opinions expressed in this posting are strictly my own 
and
> not necessarily those of my employer.


Reply by Anders Lindgren April 22, 20042004-04-22
Hi!

> the actual version is:
> #   else
> #      if defined(MSP430) && defined(__MSP430__)
> /* MSPGCC */
> #         define MSPGCC
> #         define COMPILER_OK

May I suggest that you add "defined(__GNUC__)" to this test as well?
(This symbol is defined by all gcc variants, as far as I know.)

Both the symbol MSP430 and __MSP430__ are generic and may very well be
defined by other (present or future) compilers, in which case you will
mistake them for GCC.

    -- Anders
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Reply by michelqv April 22, 20042004-04-22
For AQ430, the mnemonic is:  __AQCOMPILER__  
It is defined automatically inside the compiler, so there is no need 
to include any special .h file:
#ifdef __AQCOMPILER__
....
#endif

Michel

--- In msp430@msp4..., "Rolf F." <rolf.freitag@d...> wrote:
> Hi,
> 
> i'm using defines and ifs/elses for compiling with different 
compilers 
> and to automatize this i'm looking for
compiler (or preprocessor) 
> dependent defines .
> Does someone has  a list of macros/functions or something else 
which is 
> only availible with one compiler/preprocessor?
> 
> Rolf


Reply by Rolf F. April 22, 20042004-04-22
Hi,

because Win-XP did not flushed the buffer the last version was wrong; 
the actual version is:

// compiler autodetection
#   ifdef COMPILER_OK
#      undef COMPILER_OK
#   endif
#   ifdef __IAR_SYSTEMS_ICC__
/* This is an IAR Compiler. */
#      if (((__TID__ >> 8) & 0x7f) == 43)
/* This is the IAR MSP430 compiler. */
#         define IAR
#         if (__VER__ < 200)
/* V1.xx of the compiler. */
#            define IARV1
#            define COMPILER_OK
#         else
#            if (__VER__ < 300)
/* V2.xx of the compiler. */
#               define IARV2
#            else
#               if (__VER__ < 400)
/* V3.xx of the compiler. */
#                  define IARV3
#               endif
#            endif
#         endif
#      endif
#      if (((__TID__ >> 8) & 0x7f) == 45)
/* This is the IAR CR16C compiler. */
#         error "No MSP430 compiler."
#      else
#         if (((__TID__ >> 8) & 0x7f) == 85)
/* This is the IAR V850 compiler. */
#            error "No MSP430 compiler."
#         else
/* Unknown IAR compiler. */
#         endif
#      endif
/* This is not an IAR compiler. */
#   else
#      if defined(MSP430) && defined(__MSP430__)
/* MSPGCC */
#         define MSPGCC
#         define COMPILER_OK
#
/* MCU check */
// #ifndef __MSP430_W427__
// #  error "Wrong MCU."
// #endif
#
#      else
/* No IAR compiler, no MSPGCC */
#         error "Unknown compiler/preprocessor."
#      endif
#   endif
/* End compiler autodetection */


Rolf


Reply by Rolf F. April 22, 20042004-04-22
Hi,

ok, i forgott a flag in case a right compiler can be found:


#ifndef CONFIG_H
#   define CONFIG_H
// compiler autodetection
#   ifdef COMPILER_OK
#      undef COMPILER_OK
#   endif
#   ifdef __IAR_SYSTEMS_ICC__
/* This is an IAR Compiler. */
#      if (((__TID__ >> 8) & 0x7f) == 43)
/* This is the IAR MSP430 compiler. */
#         define IAR
#         if (__VER__ < 200)
/* V1.xx of the compiler. */
#            define IARV1
#            define COMPILER_OK
#         else
#            if (__VER__ < 300)
/* V2.xx of the compiler. */
#               define IARV2
#            else
#               if (__VER__ < 400)
/* V3.xx of the compiler. */
#                  define IARV3
#               endif
#            endif
#         endif
#      endif
#      if (((__TID__ >> 8) & 0x7f) == 45)
/* This is the IAR CR16C compiler. */
#         error "No MSP430 compiler."
#      else
#         if (((__TID__ >> 8) & 0x7f) == 85)
/* This is the IAR V850 compiler. */
#            error "No MSP430 compiler."
#         else
/* Unknown IAR compiler. */
#         endif
#      endif
/* This is not an IAR compiler. */
#   else
#      if defined(MSP430) && defined(__MSP430__)
/* MSPGCC */
#         define MSPGCC
#         define COMPILER_OK
#
/* MCU check */
// #ifndef __MSP430_W427__
// #  error "Wrong MCU."
// #endif
#
#      else
/* No IAR compiler, no MSPGCC */
#         error "Unknown compiler/preprocessor."
#      endif
#   endif
/* End compiler autodetection */
...
#endif

Rolf


Anders Lindgren schrieb:

>"Rolf F." <rolf.freitag@rolf...>
writes:
>
>  
>
>>Hi
>>
>>    
>>
>>>#ifdef __IAR_SYSTEMS_ICC__
>>>/* This is an IAR Compiler. */
>>>
>>>
>>>      
>>>
>>This works.
>>
>>    
>>
>>>#  if (((__TID__ >> 8) & 0x7f) == 43)
>>>/* This is the IAR MSP430 compiler. */
>>>
>>>#    if __VER__ < 200
>>>      
>>>
>
>How does it fail?
>
>Try to compile the following variant -- I've added #error:s to it so
>that it will report the result little bit more clearly.  I've also
>added one case at the bottom, if it triggers then you can try to
>change the initial #ifdef to "#if defined(__IAR_SYSTEMS_ICC__) ||
>defined(__IAR_SYSTEMS_ICC)", but hopefully this will not be necessary.
>
>When I apply this to our old compiler it reports:
>
>#      error "V1.xx of the compiler."
>-^
>"def.c",9  Error[141]: #error '"V1.xx of the
compiler."'
>
>Please let me know what happends when you compile the file.
>
>    -- Anders
>
>----------------------------------
>
>#ifdef __IAR_SYSTEMS_ICC__
>/* This is an IAR Compiler. */
>
>#  if (((__TID__ >> 8) & 0x7f) == 43)
>/* MSP430 */
>
>#    if __VER__ < 200
>
>#      error "V1.xx of the compiler."
>
>#    else
>
>#      error "V2.xx, or newer, of the compiler."
>
>#    endif
>
>#  elif (((__TID__ >> 8) & 0x7f) == 41)
>
>#    error "cr16"
>
>#  elif (((__TID__ >> 8) & 0x7f) == 45)
>
>#    error "cr16c"
>
>#  else
>
>#    error "unknown IAR compiler"
>
>#  endif
>
>#endif
>
>
>#if defined(__IAR_SYSTEMS_ICC) && !defined(__IAR_SYSTEMS_ICC__)
>#error "Only old symbol defined"
>#endif
>  
>



Reply by Anders Lindgren April 22, 20042004-04-22
"Rolf F." <rolf.freitag@rolf...> writes:

> Hi
>
> >#ifdef __IAR_SYSTEMS_ICC__
> >/* This is an IAR Compiler. */
> >
> >
> This works.
>
> >#  if (((__TID__ >> 8) & 0x7f) == 43)
> >/* This is the IAR MSP430 compiler. */
> >
> >#    if __VER__ < 200

How does it fail?

Try to compile the following variant -- I've added #error:s to it so
that it will report the result little bit more clearly.  I've also
added one case at the bottom, if it triggers then you can try to
change the initial #ifdef to "#if defined(__IAR_SYSTEMS_ICC__) ||
defined(__IAR_SYSTEMS_ICC)", but hopefully this will not be necessary.

When I apply this to our old compiler it reports:

#      error "V1.xx of the compiler."
-^
"def.c",9  Error[141]: #error '"V1.xx of the
compiler."'

Please let me know what happends when you compile the file.

    -- Anders

----------------------------------

#ifdef __IAR_SYSTEMS_ICC__
/* This is an IAR Compiler. */

#  if (((__TID__ >> 8) & 0x7f) == 43)
/* MSP430 */

#    if __VER__ < 200

#      error "V1.xx of the compiler."

#    else

#      error "V2.xx, or newer, of the compiler."

#    endif

#  elif (((__TID__ >> 8) & 0x7f) == 41)

#    error "cr16"

#  elif (((__TID__ >> 8) & 0x7f) == 45)

#    error "cr16c"

#  else

#    error "unknown IAR compiler"

#  endif

#endif


#if defined(__IAR_SYSTEMS_ICC) && !defined(__IAR_SYSTEMS_ICC__)
#error "Only old symbol defined"
#endif
-- 
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Reply by Rolf F. April 22, 20042004-04-22
Hi

>#ifdef __IAR_SYSTEMS_ICC__
>/* This is an IAR Compiler. */
>  
>
This works.

>#  if (((__TID__ >> 8) & 0x7f) == 43)
>/* This is the IAR MSP430 compiler. */
>
>#    if __VER__ < 200
>  
>

This does not work; it fails for the 1.26 version.

Rolf



Reply by Rolf F. April 22, 20042004-04-22
Hi,

ok,  it works :-)

Rolf

Paul Curtis schrieb:

>One assumes they are predefined like __STDC__, just
as ours are in
>CrossWorks.
>
>--
>Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
>CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors 
>
>  
>
>>-----Original Message-----
>>From: Rolf F. [mailto:rolf.freitag@rolf...] 
>>Sent: 22 April 2004 11:11
>>To: msp430@msp4...
>>Subject: Re: [msp430] Re: Compiler autodetection?
>>
>>
>>Hi,
>>
>>thanks, but which header files have to be included for these symbols?
>>
>>Rolf
>>
>>
>>rotamat2000 schrieb:
>>
>>    
>>
>>>>From mspgcc faq
(http://mspgcc.sourceforge.net/manual/x863.html):
>>>
>>>The compiler defines some symbols, so the header files and 
>>>      
>>>
>>source code
>>    
>>
>>>can easily behave in an MCU dependant manner. These are: 
>>>
>>>MSP430
>>>
>>>__MSP430__
>>>
>>>__MSP430_xxx__, where xxx is replaced by the number of the 
>>>      
>>>
>>MCU variant
>>    
>>
>>>(e.g. __MSP430_149__ is defined for the msp430x149).
>>>
>>>
>>>
>>>Patrik
>>>
>>>
>>>
>>>
>>>--- In msp430@msp4..., Anders Lindgren <andersl@i...> wrote:
>>> 
>>>
>>>      
>>>
>>>>"Rolf F." <rolf.freitag@d...> writes:
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>>>i'm using defines and ifs/elses for compiling with
different
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>compilers
>>> 
>>>
>>>      
>>>
>>>>>and to automatize this i'm looking for compiler (or
preprocessor) 
>>>>>dependent defines . Does someone has  a list of 
>>>>>          
>>>>>
>>macros/functions or 
>>    
>>
>>>>>something else
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>which is
>>> 
>>>
>>>      
>>>
>>>>>only availible with one compiler/preprocessor?
>>>>>     
>>>>>
>>>>>          
>>>>>
>>>>Hi!
>>>>
>>>>For the IAR compilers you can use check the symbol 
>>>>__IAR_SYSTEMS_ICC__.  It is defined in all our compilers.
>>>>
>>>>If you would like to distinguish between different IAR compilers
>>>>   
>>>>
>>>>        
>>>>
>>>then
>>> 
>>>
>>>      
>>>
>>>>the moders one sets e.g. __ICC430__ or __ICCAVR__ for our msp430
or 
>>>>avr compiler, respectively.  Unfortunately, this is not defined
for 
>>>>the old compiler.  (The older ones used a now depreciated macro 
>>>>__TID__ for this.  It is still present in all our compilers but
we
>>>>   
>>>>
>>>>        
>>>>
>>>do
>>> 
>>>
>>>      
>>>
>>>>not recommend that you use it for code that is not intended to
be 
>>>>runed on older compiler.  However, in this case it is
appropriate.)
>>>>
>>>>To find the exact compiler version you can use the macro
__VER__, 
>>>>which is an integer on the form: MajorVersioNumber*100 + 
>>>>MinorVersioNumber.  For example for V3.10 this has the value
310.
>>>>
>>>>So, to put everything together:
>>>>
>>>>
>>>>#ifdef __IAR_SYSTEMS_ICC__
>>>>/* This is an IAR Compiler. */
>>>>
>>>>#  if (((__TID__ >> 8) & 0x7f) == 43)
>>>>/* This is the IAR MSP430 compiler. */
>>>>
>>>>#    if __VER__ < 200
>>>>
>>>>/* V1.xx of the compiler. */
>>>>
>>>>#    else
>>>>
>>>>/* V2.xx, or newer, of the compiler. */
>>>>
>>>>#    endif
>>>>
>>>>#  elif (((__TID__ >> 8) & 0x7f) == 45)
>>>>/* This is the IAR CR16C compiler. */
>>>>
>>>>#  elif (((__TID__ >> 8) & 0x7f) == 85)
>>>>/* This is the IAR V850 compiler. */
>>>>
>>>>#  else
>>>>/* Unknown IAR compiler. */
>>>>
>>>>#  endif
>>>>
>>>>#else
>>>>/* This is not an IAR compiler. */
>>>>
>>>>#endif
>>>>
>>>>   -- Anders Lindgren, IAR Systems
>>>>--
>>>>Disclaimer: Opinions expressed in this posting are strictly my
own 
>>>>   
>>>>
>>>>        
>>>>
>>>and
>>> 
>>>
>>>      
>>>
>>>>not necessarily those of my employer.
>>>>   
>>>>
>>>>        
>>>>
>>>
>>>
>>>.
>>>
>>>
>>>Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>> 
>>>
>>>      
>>>
>>
>>
>>------------------------ Yahoo! Groups Sponsor 
>>---------------------~--> Buy Ink Cartridges or Refill Kits 
>>for your HP, Epson, Canon or Lexmark Printer at MyInks.com.  
>>Free s/h on orders $50 or more to the US & Canada. 
>>    
>>
>http://www.c1tracking.com/l.asp?cidU11
>http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/CFFolB/TM
>---------------------------------~->
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>
>.
>
> 
>Yahoo! Groups Links
>
>
>
> 
>
>
>  
>