多练练英语水平对你也有好处:)

showmetheway 2003-02-02 10:38:13
#pragma token-string

The token-string is a series of characters that gives a specific compiler instruction and arguments, if any. The number sign (#) must be the first non-white-space character on the line containing the pragma; white-space characters can separate the number sign and the word pragma. Following #pragma, write any text that the translator can parse as preprocessing tokens. The argument to #pragma is subject to macro expansion.

If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.

Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler. The C and C++ compilers recognize the following pragmas:

alloc_text comment init_seg1 optimize
auto_inline component inline_depth pack
bss_seg data_seg inline_recursion pointers_to_members1
check_stack function intrinsic setlocale
code_seg hdrstop message vtordisp1
const_seg include_alias once warning

//////////////////////////////
敢问各位个大哥,以上所述到底是什么个意思?
...全文
38 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
Richuen22 2003-02-04
  • 打赏
  • 举报
回复
I don't know English。^_^
AthlonxpX86 2003-02-04
  • 打赏
  • 举报
回复
说笑啊,1000个我也搞不定啊早说过了,我英语连初中都没毕业
showmetheway 2003-02-04
  • 打赏
  • 举报
回复
好建议,你来搞定吧。。
AthlonxpX86 2003-02-04
  • 打赏
  • 举报
回复
我们不如专门立个项目来翻译MSDN吧!!!
Cline 2003-02-04
  • 打赏
  • 举报
回复
不,这是MS的编译器之选项耳。
showmetheway 2003-02-04
  • 打赏
  • 举报
回复
本来是一个问题,现在变两个了:)
qing_li73 2003-02-03
  • 打赏
  • 举报
回复
pack
#pragma pack( [ n] )

Specifies packing alignment for structure and union members. Whereas the packing alignment of structures and unions is set for an entire translation unit by the /Zp option, the packing alignment is set at the data-declaration level by the pack pragma. The pragma takes effect at the first structure or union declaration after the pragma is seen; the pragma has no effect on definitions.

When you use #pragma pack(n), where n is 1, 2, 4, 8, or 16, each structure member after the first is stored on the smaller member type or n-byte boundaries. If you use #pragma pack without an argument, structure members are packed to the value specified by /Zp. The default /Zp packing size is /Zp8.

The compiler also supports the following enhanced syntax:

#pragma pack( [ [ { push | pop}, ] [ identifier, ] ] [ n ] )

This syntax allows you to combine program components into a single translation unit if the different components use pack pragmas to specify different packing alignments.

Each occurrence of a pack pragma with a push argument stores the current packing alignment on an internal compiler stack. The pragma’s argument list is read from left to right. If you use push, the current packing value is stored. If you provide a value for n, that value becomes the new packing value. If you specify an identifier, a name of your choosing, the identifier is associated with the new packing value.

Each occurrence of a pack pragma with a pop argument retrieves the value at the top of an internal compiler stack and makes that value the new packing alignment. If you use pop and the internal compiler stack is empty, the alignment value is that set from the command-line and a warning is issued. If you use pop and specify a value for n, that value becomes the new packing value. If you use pop and specify an identifier, all values stored on the stack are removed from the stack until a matching identifier is found. The packing value associated with the identifier is also removed from the stack and the packing value that existed just before the identifier was pushed becomes the new packing value. If no matching identifier is found, the packing value set from the command line is used and a level-one warning is issued. The default packing alignment is 8.

The new, enhanced functionality of the pack pragma allows you to write header files that ensure that packing values are the same before and after the header file is encountered:

/* File name: include1.h
*/
#pragma pack( push, enter_include1 )
/* Your include-file code ... */
#pragma pack( pop, enter_include1 )
/* End of include1.h */

In the previous example, the current pack value is associated with the identifier enter_include1 and pushed, remembered, on entry to the header file. The pack pragma at the end of the header file removes all intervening pack values that may have occurred in the header file and removes the pack value associated with enter_include1. The header file thus ensures that the pack value is the same before and after the header file.

The new functionality also allows you to use code, such as header files, that uses pack pragmas to set packing alignments that differ from the packing value set in your code:

#pragma pack( push, before_include1 )
#include "include1.h"
#pragma pack( pop, before_include1 )

In the previous example, your code is protected from any changes to the packing value that might occur in include.h.
AthlonxpX86 2003-02-03
  • 打赏
  • 举报
回复
具体怎么算啊,还是不明白
everandforever 2003-02-03
  • 打赏
  • 举报
回复
对了,“老师”的确是真不敢当。
everandforever 2003-02-03
  • 打赏
  • 举报
回复
字节对齐你也不知道?如 Cline(营营) 所说:

结构
struct TestStruct
{
char a;
int b;
}
如对齐方式为一个字节,那么sizeof(TestStruct)==5, 如果为四字节,那么sizeof(TestStruct)==8;
AthlonxpX86 2003-02-03
  • 打赏
  • 举报
回复
请尊敬的everandforever(Forever)老师给我们好好讲一课,
我一定做个好学生,这些问题我真的不知道啊
everandforever 2003-02-03
  • 打赏
  • 举报
回复
字节对齐问题。你会碰到的。
showmetheway 2003-02-03
  • 打赏
  • 举报
回复
pack是什么意思也不知道,我还是先把刀磨快点(磨到有刀哥的一半快)再来问这个问题吧:)
Cline 2003-02-02
  • 打赏
  • 举报
回复
举个例,比如pack
#pragma pack.....
它能告诉编译器数据的对齐方式。

如结构
struct TestStruct
{
char a;
int b;
}
如对齐方式为一个字节,那么sizeof(TestStruct)==5,如果为四字节,那么sizeof(TestStruct)==8;
kingcom_xu 2003-02-02
  • 打赏
  • 举报
回复
你们都是绅士:)
everandforever 2003-02-02
  • 打赏
  • 举报
回复

如果编译器碰到一个不认识的命令,它只产生一个警告,但编译继续。

pragma 可以用在条件编译中,用来提供新的预编译功能,或者向编译器提供预先定义的编译条件。 C 和 C++ 编译器认识下列参数:

...
________
I LIKE GIRLS.
everandforever 2003-02-02
  • 打赏
  • 举报
回复
#pragma 命令行

命令行是一系列的字符,用以给予编译器指示和参数。如果程序中有“pargma”这么一行,那么它的第一个 非空格(NON-WHITE-SPACE)字符(比如 空格,TAB 等等) 必须是“#”。空格符可以用来分隔数字和字符参数。在 #pragma 后面,可以写上任何翻译器可以认出的命令。
liufucsdn 2003-02-02
  • 打赏
  • 举报
回复
我也不知道!
showmetheway 2003-02-02
  • 打赏
  • 举报
回复
AthlonxpX86(一滴水) :
#pragma 这个你以前没见过?
AthlonxpX86 2003-02-02
  • 打赏
  • 举报
回复
应该是与编译指令中的什么东西吧
加载更多回复(2)

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧