What is the IAR equivalent of '__attribute__ (

2019-06-10 06:07发布

I was using LPC series (NXP) as control something. And now, we are switching over to another MCU (Spansion) and the compiler is from GNU to IAR. Some attribute doesn't the same between IAR and GNU, I would like to ask for help:

In the past (GNU):

#define ALIAS(f) __attribute__((weak, alias (#f)));
#define CSV_IRQHandler(void)   ALIAS(IntDefaultHandler)

What is different if the compiler change to IAR?

If I use the same syntax I get the error:

Error[Pe130]: expected a "{"

Any suggestion would be appreciated!

标签: gnu iar
1条回答
我命由我不由天
2楼-- · 2019-06-10 06:55

You should be able to use #pragma weak CSV_IRQHandler=IntDefaultHandler

From the "IAR C/C++ Development Guide"

weak

Syntax           #pragma weak symbol1={symbol2}

Parameters       symbol1 A function or variable with external linkage
                 symbol2 A defined function or variable.

Description      This pragma directive can be used in one of two ways:
                 ● To make the definition of a function or variable with external linkage a weak
                   definition. The __weak attribute can also be used for this purpose.
                 ● To create a weak alias for another function or variable. You can make more                
                   than one alias for the same function or variable.

 Example        To make the definition of foo a weak definition, write:

                #pragma weak foo

                To make NMI_Handler a weak alias for Default_Handler, write:

                #pragma weak NMI_Handler=Default_Handler

                If NMI_Handler is not defined elsewhere in the program, all references to 
                NMI_Handler will refer to Default_Handler.
查看更多
登录 后发表回答