定义的含义 [英] meaning of define
问题描述
以下定义的含义是什么: -
#define x(argl ...)x1(## argl)
What is meaning of the following define:-
#define x(argl...) x1(##argl)
推荐答案
ni ********** @ gmail.com 写道:
以下定义的含义是什么: -
#define x( argl ...)x1(## argl)
What is meaning of the following define:-
#define x(argl...) x1(##argl)
我不认为C ++中允许使用变量宏,所以......部分是
不标准。 ##是令牌粘贴运算符。它会粘贴您传递的令牌
作为参数。例如宏
#define var(n)var ## n
会导致''var(3)''扩展为''var3''。
问候,
Bart。
I don''t think variadic macros are allowed in C++, so the ... part is
not standard. The ## is the token pasting operator. It pastes the token
that you pass as an argument. For example the macro
#define var(n) var##n
would cause ''var(3)'' to be expanded to ''var3''.
Regards,
Bart.
Bart写道:
Bart wrote:
ni * *********@gmail.com 写道:
以下定义的含义是什么: -
#define x(argl ...)x1(## argl)
What is meaning of the following define:-
#define x(argl...) x1(##argl)
我不认为C ++中允许使用变量宏,所以...部分是
不标准。 ##是令牌粘贴运算符。它会粘贴您传递的令牌
作为参数。例如宏
#define var(n)var ## n
会导致''var(3)''扩展为''var3''。
问候,
巴特。
I don''t think variadic macros are allowed in C++, so the ... part is
not standard. The ## is the token pasting operator. It pastes the token
that you pass as an argument. For example the macro
#define var(n) var##n
would cause ''var(3)'' to be expanded to ''var3''.
Regards,
Bart.
我试过这个并编译c ++编译器,但如果你尝试
就像
#define x(argl,...)x1(## arl)
或
#define x(...)x1(##)
编译器抛出错误。那么你能解释一下这是如何扩展的吗?我认为
认为变量参数的正常语法是foo(有些arg,...)
或者只是foo(...)。
谢谢,
Niraj
I have tried this and this compiles on c++ compiler but if you try
something like
#define x(argl,...) x1(##arl)
or
#define x(...) x1(##)
compiler throws error. So can you explain how this is being expanded? I
think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
Thanks,
Niraj
## C ++中的运算符用于宏内部连接两个令牌为
示例: -
#include< iostream>
使用命名空间std;
#define func(x)x ## out<<"" Hello!"<< endl
int main(){
func(c);
系统(暂停);
}
以上程序将打印Hello!在屏幕上。
## operator in C++ is used inside macros to concatenate two tokens for
example :-
#include <iostream>
using namespace std;
#define func(x) x##out<<"Hello!"<<endl
int main(){
func(c);
system("pause");
}
Above programme will print Hello! on screen.
我试过这个并编译c ++编译器,但如果你尝试
就像
#define x(argl,...)x1(## arl)
或
#define x(...)x1(##)
编译器抛出错误。那么你能解释一下这是如何扩展的吗?我认为
认为变量参数的正常语法是foo(有些arg,...)
或者只是foo(...)。
谢谢,
Niraj
I have tried this and this compiles on c++ compiler but if you try
something like
#define x(argl,...) x1(##arl)
or
#define x(...) x1(##)
compiler throws error. So can you explain how this is being expanded? I
think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
Thanks,
Niraj
这篇关于定义的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!