【问题标题】:How could these token-strings be defined如何定义这些令牌字符串
【发布时间】:2021-09-28 02:41:07
【问题描述】:

我的问题是关于 #define 指令。 在documentation 我们有:

语法

#define identifier token-string
#define identifier ( identifier, ... , identifier ) token-string

备注中是这样写的:

token-string 参数由一系列标记组成,例如关键字、常量或完整语句。

我的问题是如何在 C 中定义关键字、常量、完整语句、指令和命令。

我已经对它们中的每一个都有一个“经验”的想法,但我无法用语言来定义它们。

如果你们能帮助我,我将不胜感激,如果可能,请提供一些示例以便更好地理解。

【问题讨论】:

标签: c command token c-preprocessor instructions


【解决方案1】:

测试一下:

#define macro(A, B, C) A; B; C;
macro(int i=0, int x = i + 1, printf("%d\n", x));
//expands to: int i=0; int x = i + 1; printf("%d\n", x);

#define macro(Type, Id) Type##Id
macro(int, array) //expands to: intarray

#define macro(X) #X
macro(x + y) //expands to: "x + y"

如您所见,您可以将各种东西作为参数传递给“宏之类的函数”。

更多信息:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-11
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    相关资源
    最近更新 更多