Source code reusability

Charles-Antoine Gauthier charles.gauthier at nrc.ca
Mon Oct 23 15:40:53 UTC 2000


The GCC team recommends the use of __attribute__ over pragma. Look in
the docs under C extensions, function attributes.

  Some people object to the `__attribute__' feature, suggesting that
  ANSI C's `#pragma' should be used instead.  There are two reasons for
  not doing this.

    1. It is impossible to generate `#pragma' commands from a macro.

    2. There is no telling what the same `#pragma' might mean in another
       compiler.

The documentation also contains:

`interrupt'
     Use this option on the M32R/D to indicate that the specified
     function is an interrupt handler.  The compiler will generate
     function entry and exit sequences suitable for use in an interrupt
     handler when this attribute is present.

`interrupt_handler'
     Use this option on the H8/300 and H8/300H to indicate that the
     specified function is an interrupt handler.  The compiler will
     generate function entry and exit sequences suitable for use in an
     interrupt handler when this attribute is present.

Unless you are using either of these CPUs, I would not assume that
#pragma interrupt does anything. 


Silverio Diquigiovanni wrote:
> 
> Hi to all,
> 
> I'm aware that this isn't a good request to submit to this mail list,
> but with faith in your experience in matter of reusable source code I
> hope you can help me.
> 
> The question:
> 
> - I have three compilers which I normally use every day :
> 
>   Green Hills compiler
>   GNU gcc compiler
>   IAR compiler
> 
> The source code is largely reusable because I use always ANSI compliant
> normative, but today have a problem with interrupt functions.
> 
> I must create a mechanism for declarin a function like interrupt
> function whitout use a compiler dipendent syntax.
> 
> Green Hills uses :
>   void interrupt my_fun( void ) { }
> 
> GNU uses:
>   #pragma interrupt
>   void my_fun( void ) { }
> 
> IAR uses:
>   void interrupt[vect_num] my_fun( void ) { }
> 
> My initial idea was be usign a macro to implement the different
> compiler implementation.
> 
> #ifdef __GREEN_HILLS__
>   #define INTERRUPT_FUN(fun,vec)        (.........)
> #endif
> #ifdef __GNUC__
>   #define INTERRUPT_FUN(fun,vec) (#pragma interrupt \ void fun(void))
> #endif
> #ifdef __IAR__
>   #define INTERRUPT_FUN(fun,vec) (void interrupt[vec] fun(void))
> #endif
> 
> But #pragma can't be generated by a macro, so the __GNUC__
> implementation is impossible....
> 
> Have you some suggestion about ?
> 
> Thank you in advance,
> Best Regards
> 
> Silverio Diquigiovanni

-- 
Charles-Antoine Gauthier
Institute for Information Technology   Institut de technologie de
l'information
National Research Council of Canada    Conseil national de recherches du
Canada



More information about the users mailing list