当前位置:网站首页>Nonstandard compiler attribute extension
Nonstandard compiler attribute extension
2022-06-13 05:01:00 【Snow * sleet * snow】
As C Standard extension , Some compilers allow functions 、 Variables or types use some nonstandard properties . In brief, these macros are used for compiler optimization .GNU Compiler collection (GCC) and LLVM/Clang Use __attribute__ Syntax to specify these attributes . Different compilers may support different properties , It is also possible to use a completely different syntax .
NetBSD Code should generally avoid direct use __attribute__ Or some other similar syntax provided by a particular compiler .
however NetBSD The in <sys/cdefs.h> The following attribute macros are provided in the header file , These attribute macros can be automatically extended to the corresponding compiler syntax .
__dead __pure __constfunc __noinline __unused __used __diagused __debugused __packed __aligned(x); __section(section); __read_mostly __cacheline_aligned __predict_true(exp); __predict_false(exp); __printflike(fmtarg, firstvararg); __sysloglike(fmtarg, firstvararg);
__dead
Certain functions, such as abort(3) and exit(3), can never return.
Some functions such as abort(3),exit(3), There is no return value . When used _dead When you declare a function , The compiler can do some optimization , Related warning May also be removed . Obviously with _dead Decorated functions except void No other types will be returned ._dead This is to tell the compiler that it can let go and optimize . similar __attribute__((noreturn)).
__pure
By __pure Modified function , Is defined as a function that has no effect other than the return value , The return value is assumed to depend only on function parameters and / Or global variables , For parameters and / Or global variables must also be read-only . If a function is to be correct volatile Variable ( Register variables, etc ) To read and write , Or access system resources that can be changed between successive calls , Can't use __pure Of . And __pure The equivalent function attribute is _attribute__((const))
__constfunc
__constfunc It's better than __pure More stringent variants , except __pure Beyond the limits of , The function it modifies can never access global variables , Nor can I get a pointer as a parameter . __constfunc The return value of the decorated function must only depend on the parameters passed by the value .
边栏推荐
- 约瑟夫问题
- Section 8 - Practical commissioning techniques
- Chapter 14 introduction: memory operation API
- C language learning log 10.5
- Bm1z002fj-evk-001 startup evaluation
- 详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
- Embedded hardware: electronic components (1) resistance capacitance inductance
- QT direction key to move focus
- Clause 30: be familiar with the failure of perfect forwarding
- Solution to sudden font change in word document editing
猜你喜欢
The games that you've tasted
Bomb disposal cat
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
Chapter 2 process management
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
Explain the role of key attribute in V-for
MySQL8.0.13安装教程(有图)
BM1Z002FJ-EVK-001开机测评
Kaggle time series tutorial
Advanced C language - Section 1 - data storage
随机推荐
Reductive elimination
Section 5 - Operator details
1.2 differences caused by keywords
Chapter 14 introduction: memory operation API
Four methods for judging JS data types and user-defined methods
Cesium:cesiumlab makes image slices and loads slices
Mysql8.0.13 installation tutorial (with pictures)
Elliptic curve encryption
OJ problem solution summary
Conception d'un système basé sur MVC avec javaswing JDBC
Configuration used by automatic teaching evaluation script
About mission planning and improving execution
Robot pose description and coordinate transformation
Luogu p3654 fisrt step
[JS solution] leedcode 200 Number of islands
Clause 32: moving objects into closures using initialization capture objects
Red Treasure Book Reading Notes (continuously updated)
Luogu p1012 guess
C language learning log 1.24
【多线程编程】Future接口获取线程执行结果数据