字符串变量中使用的宏定义
Macro definitions used in the string variable
我想实现这个:
#include <stdio.h>
#define STR_HELLO_LEN 10
#define str(opt) STR_###opt##_LEN
int main(int argc, char **argv)
{
char *tmp = "hello";
int y=str(tmp); // y = STR_HELLO_LEN,but is STR_tmp_LEN
return(0);
}
y = STR_HELLO_LEN,但STR_tmp_LEN
这是不可能的。所有宏都在编译时解析。"hello"只在运行时真正存在。
相关文章:
- 在头文件中定义变量不会出错
- C++宏定义和取消定义
- 根据 c++ 标准在该宏定义中推送/弹出宏时的行为是什么
- VS2017 #error: : snprintf 的宏定义与标准库函数声明冲突
- 如何使用 SFINAE 在方法调用中有条件地定义变量?
- 宏定义不正确没有错误
- 在命名空间中定义变量
- Visual Studio:snprintf 冲突的宏定义
- 宏定义中的预处理器令牌两边有两个双引号
- CMake 添加和删除宏定义以编译共享库/可执行文件
- 是否可以在C++中基于程序集输出(.dll或.exe)定义变量
- 宏C++#定义示例(对象)(::f(s,(对象),arg1,arg2,arg3)
- 用不同类型重新定义变量
- 具有全局定义变量的递归比没有全局定义变量的递归函数获得更多的堆栈.为什么?(跳入C++)
- 字符串变量中使用的宏定义
- 带有变量和类型的C++03宏定义
- 基于宏定义具有多个类型的一个变量的可能性
- 如何将系统环境变量作为宏定义放入C头文件
- 用模板定义宏作为变量
- 可以将整数变量附加到宏定义的函数上吗?