Keyword extern, cregister, near, far, restrict, volatile in DSP

Source: Internet
Author: User

Extern: extern can be placed before a variable or function to indicate that the definition of a variable or function is in another file, prompting the compiler to find its definition in other modules when it encounters this variable and function. In addition, extern can be used to specify links.

Const: You can use const to define some variables or arrays to ensure that their values are not changed.

For example, int * const P = & X; defines a constant pointer P to the variable Int.

Const int * q = & X; defines a variable pointer Q to the constant Int.

Cregister: defines variables used to directly access the CPU control register.

You can first define a header file to define this variable (actually the corresponding register ),
Then directly reference these variables in the corresponding C source code.
To define these variables, follow these steps:
Extern cregister volatile unsigned int register;
Here, register is a register such as AMR, CSR, and IFR.
For example:
Extern cregister volatile unsigned int AMR;
Extern cregister volatile unsigned int CSR;
Extern cregister volatile unsigned int IFR;
Extern cregister volatile unsigned int ISR;
Extern cregister volatile unsigned int MRM;
Extern cregister volatile unsigned int ier;
Extern cregister volatile unsigned int FADCR;
Extern cregister volatile unsigned int faucr;
Extern cregister volatile unsigned int fmcr;
Main ()
{
Printf ("AMR = % x/N", Amr );
}
Interrupt: the interrupt keyword is used to define an interrupt service function. The interrupt service function must store the interrupt control register and return sequence. When a C/C ++ program is interrupted, the interrupt service program will save all the registers used.

Interrupt void int_handler ()
{
Unsigned int flags;
...
}

Near and far: used to define the function call method and the access to global variables and static variables when the function is called.

Global and static variables can be declared as near or far, and near and far are type modifiers.

The variables declared as near adopt the relative addressing of registers. The base register is the Data Pointer dp (32 bits), and the offset

The address is a 15-bit constant. Therefore, the near global and static variables cannot exceed 32 bytes;

Variables declared as far are indirectly addressable by registers, and can be addressable to any space without size restrictions;

The near variable executes two statements less during access than the far variable.

Restrict:

The restrict keyword is used to modify pointers, references, and array variables. It indicates the objects indicated by pointers within the valid range of variables.

This pointer is used only for reference.

Volatile:

Easy to change (C: Like const, volatile is a type modifier (type specifier ). It is designed to modify variables accessed and modified by different threads .)
It is recommended that a variable defined as volatile be changed unexpectedly, so that the compiler will not assume the value of this variable. Precisely, the optimizer must carefully re-read the value of this variable every time when using this variable, rather than using the backup stored in the register.

From: http://blog.csdn.net/x111y1j1/article/details/6283811

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.