znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
阅读:782回复:0

Pragma Directives in c/c++

楼主#
更多 发布于:2002-06-21 14:43
Pragma Directives of lcc-win32
Packing directives. These directives tell the compiler how to pack the structure members.

This directive can have two forms:

#pragma pack(n)

where n is 1,2,4,8, or 16. This will align the members of a structure at 1 (i.e., no packing) at 2, 4, 8, or 16 bytes.

You can also use:

#pragma pack(push,n)

This will save the current value of the packing constant, and set it to n, which should be an integer as explained above. After some code, this allows you  to use:

#pragma pack(pop)

to restore the original value again.

Example:

The most common use is at the beginning of an include file to set the value to a certain amount, and to restore it at the end of the file.

#pragma pack(push,1)

.....

#pragma pack(pop)

EOF

Include directives. The pragma

#pragma once

will ensure that the current file will be read only once by the compiler. Any further directives for #including the same file will have no affect.

Optimization directives. This allows you to set the optimization flag on or off at certain functions.

#pragma optimize(n)

where n will be either zero (no optimizations) or one (optimizations).

Switch generation control. The pragma

#pragma density(push,0.0)

will trigger the compiler to generate a table of all possible switch values between the lowest and the highest case statements found, making a tradeoff that penalizes space for speed. This can of course overflow if you have:

     switch(i) {

     case -10000000:

          ...

     case 10000000:

          ...

     }

In this example, the generated table would have 20 million positions, which may not be a good idea.

On the contrary, in other cases where the numbers are densely packed, this can be an ideal optimization.

http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
游客

返回顶部