#pragma
#pragma lexems
- pragma命令赋予程序员控制编译器的能力,由于#prama的实现依赖于编译器,使用方法因编译器而异。一个选项可能完全改变程序执行顺序。
下边列出一些编译器在所支持的操作系统中实现的一些常用的编译器自定义参数。
pragma 也允许程序员设定特定函数,使它在主函数执行之前或者主函数退出时被调用。
#pragma startup fun() //The function must have return void type & no parameters. #pragma exit fun1()
目录 |
[编辑] GNU C Compiler (GCC) - GNU/Linux, BSD, GNU/Hurd, GNU/Darwin/Mac OS X, Windows (MinGW)
[编辑] redefine_extname
#pragma redefine_extname printf prnt
Gives C functions a different programmer defined symbol when translated to assembly language.
[编辑] extern_prefix
#pragma extern_prefix ext_ // begin prefixing // your external symbols with the assembly prefix is here #pragma extern_prefix // end prefixing
Prefixes all external function assembly symbols with the string prefix. Another #pragma extern_prefix will end prefixing of externals.
[编辑] pack
#pragma pack(64) // optimize all subsequent classes, unions, and structures for 64 bit code
Packing is an optimization method that makes the members of structures, classes, and unions align to a factor of the packing boundary. This usually makes it easier (thus faster) for the processor to access data since it's packed to align with what the processor is used to dealing with, however it costs memory by having random unnecessary garbage data inserted to align the code with the pack. the numerical value in parenthesis must be a factor of 2 (2, 4, 8, 16, 32, 64....). There are other ways to use "pack" and they're described below but above is the simplest and most common way. you can use
#pragma pack() /* with empty parenthesis */
to reset the packing to the compiler default.
<- #pragma pack(push) and #pragma pack(pop) are on the way, I'm still researching them and their functionality. -/>
<- This document is still under construction, I intend to continue adding compilers and their pragma options instead of leaving this largely blank. -GinoMan -/>