#define 带参数...为什么这样有效?
这是怎么回事?
#define CONSTANT_UNICODE_STRING(s) \
{ sizeof( s ) - sizeof( WCHAR ), sizeof(s), s }
.
.
.
.
UNICODE_STRING gInsufficientResourcesUnicode
= CONSTANT_UNICODE_STRING(L"[-= Insufficient Resources =-]");
这段代码正在运行。
我需要查看预处理器扩展, 宏定义中的逗号怎么了?
What is going on here?
#define CONSTANT_UNICODE_STRING(s) \
{ sizeof( s ) - sizeof( WCHAR ), sizeof(s), s }
.
.
.
.
UNICODE_STRING gInsufficientResourcesUnicode
= CONSTANT_UNICODE_STRING(L"[-= Insufficient Resources =-]");
This code is working.
I need to see the pre-processors expansion,
and whats up with commas in macro definition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
UNICODE_STRING
在
中定义为具有两个大小的类型,后跟一个指向字符串的指针。宏中的逗号分隔结构中字段的值。
UNICODE_STRING
is defined in<winternl.h>
as a type that has two sizes followed by a pointer to a string.The commas in the macro separate the values for the fields in the structure.
宏不是作为“函数”运行的;而是作为“函数”运行的。逗号在那里是因为它是结构初始化。
大概有一个名为
UNICODE_STRING
的结构,其中定义了三个字段。该宏允许您根据正在使用的字符串一次性初始化结构,并适当地填写大小字段。最后一条语句相当于写:
The macro isn't functioning as a "function"; the commas are there because it's a struct initialization.
Presumably there is a structure somewhere called
UNICODE_STRING
defined with three fields in it. The macro allows you to initialize the struct in one go based on the string you're using, and fills out the size fields appropriately.The last statement is equivalent to writing:
通常,您可以通过使用
gcc
向编译器提供-E
选项而不是-c
选项来获得源文件的预处理器扩展举个例子:在类 UNIX 系统(linux、OS X)上,您通常还有一个名为
cpp
的独立预处理器。Usually you may get the preprocessor expansion of a source file by giving the
-E
option to the compiler instead of the-c
option, withgcc
as an example:on unix like systems (linux, OS X) you often also have a stand-alone preprocessor called
cpp
.它扩展为一个结构初始值设定项。
All it expands to is a struct initializer.
它扩展为:
基本上它初始化一个包含 3 个成员的结构。一是不带空终止符的常量字符串的长度。接下来是带有空终止符的字符串的长度,最后一个是实际字符串。逗号只是结构初始化形式的一部分。
Well it expands to:
Basically its initialising a struct that contains 3 members. One is the length of the constant string without the null terminator. The next is the length of the string WITH the null terminator and the final is the actual string. The commas are just part of the struct initialisation form.