Special keywords in c/C + +: Volatile, register, restrict, __attribute__

Source: Internet
Author: User
Tags volatile

1.volatile: tells the compiler that I can change at any time, each time it is used, it must be read from the address of I (memory), instead of using the cache value in the Register;

volatileint i=10

2.Register: The variable declared with the modifier register belongs to the Register storage type. This type is similar to the automatic storage type and has an automatic storage period, code block scope, and internal connection. Declaring a register is just a request, so the variable may still be a normal automatic variable. In either case, a variable modified with register cannot get an address. If it is not initialized, its value is undefined.

3.Restrict: The keyword restrict is used only to qualify pointers, which is used to tell the compiler that all actions that modify the pointer to the content are based on the pointer (base on) , that there is no other way to modify the operation The consequence is to help the compiler do better code optimization and generate more efficient assembly code.

int *restrict//只会通过指针 x,对 x 中的值进行修改 

Reference: http://blog.csdn.net/lovekatherine/article/details/1891806

4. __attribute__ : You can set function properties (functions Attribute), variable properties (Variable Attribute), and type properties (types Attribute).

externvoid myexit() __attribute__((noreturn));//表示函数不存在返回值;编译不会再出现警告信息。

Reference: http://blog.csdn.net/ruixj/article/details/4274721

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Special keywords in c/C + +: Volatile, register, restrict, __attribute__

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.