#pragma commands and Extended keywords commonly used in IAR

Source: Internet
Author: User

pragma command

1. #pragma message ("")
The compiler compiles here to print the appropriate text information in the build window.

2. #pragma error ""
The compiler compiles here, generating an error in the build window and printing its textual information.

3. #pragma inline [=forced | never]
With this directive, it is recommended to compile the function of the function behind the instruction to the body of the function calling it.
When #pragma inline = forced, the compiler is forced to inline the function, and if the inline is unsuccessful, a warning message is issued.

4. #pragma location = {Address | register | NAME}
The directive is useful
1) Locate the global or static variable after the instruction to the specified absolute address. Where the variable must be defined as __no_init ============address (address)
pragma location = address is equivalent to @ address, where the variable must also be defined as __no_init.
Example:
__no_init volatile Char Alpha @ 0xff2000
Use absolute address location, also need to pay attention to address alignment problem.

2) Locate the variable after the instruction in the specified register, where the variable must be declared as __no_init, and the scope of the variable is the entire file. =============register (Register R4-r11)
pragma location = Register is equivalent to @ Register, where the variable must also be defined as __no_init

3) Place the function or variable after the instruction in a specified section. Do not attempt to place variables that are normally placed in different sections in the same section.
=============name (a user-defined section name; Cannot is a section name predefined for use by the compiler and linker.
pragma location = section equivalent to @ section

Example
The variable is placed in a custom section.
__no_init int Alpha @ "My_noinit"; /* OK */
#pragma location= "My_constants"
const int Beta; /* OK */

The function is placed in a custom section.
void f (void) @ "my_functions";
void g (void) @ "My_functions"
{
}
#pragma location= "My_functions"
void h (void);

5. #pragma required = symbol
#pragma required ensure that the link output includes another symbol that is required for a symbol. The directive must be placed immediately before the second symbol. If the symbol is not visible in the app, use the directive. For example, if you only indirectly reference a variable by its segment, you must use #pragma required.
eg
const char copyright[] = "Copyright by Me";
#pragma required=copyright
int main ()
{
/* do something here. */
}
Even if the copyright string is not used by the application, it'll still be included by the
Linker and available in the output.

Extended keywords
__no_init
Normally, when an application starts, the IAR runtime environment initializes all global and static variables to 0. The IAR C compiler supports declaring uninitialized variables, using the __no_init type qualifier. Variables that declare __no_init do not need to be initialized. Some key data cannot be changed when the system resets (such as a watchdog reset or other cause of reset)! In this case, the __no_init can be qualified.

__root
__root defined functions and variables that are not referenced by any function are still present in the target code and are not optimized.

__task
A function that is qualified by this keyword does not register protection when it is called, that is, there is no register-in-stack operation. Usually used in the startup function of the RTOs.
By default, functions save the contents of used preserved registers on the stack upon entry, and restore them at exit. Functions that is declared __taskdo not the save all registers, and therefore require less stack space.
Because a function declared __taskcan corrupt registers that is needed by the calling function, you should only use __tas Kon functions that does not return or call such a function from assembler code.
The function Maincan be declared __task, unless it's explicitly called from the
Application. In real-time applications with more than one task, the root function of each task can be declared __task.
In the IAR experiment, found that the compiler or register to do the stack operation, do not know why?

#pragma commands and Extended keywords commonly used in IAR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.