在编译时为变量赋值
Assign a value to a variable at compilation time
我想
在编译代码时为变量分配一个特定的值(对于 C 和 C++):
例如:
//test.c
int main()
{
int x = MYTRICK ; (edit: changed __MYTRICK__ to MYTRICK to follow advices in comment)
printf ("%dn", x);
return 0;
}
比林能够做这样的事情:
gcc -XXX MYTRICK=44 test.c -o test
并因此:
$./test
44
使用-D
选项:
gcc -DMYTRICK=44 test.c -o test
并在程序中使用MYTRICK
宏,而不是__MYTRICK__
.以 __
开头的名称由实现保留。
相关文章:
- 为"adjacent"变量赋值时出现问题
- 为什么我不能在返回 const 的布尔函数中为类成员变量赋值?C++
- c++问题:给一个变量赋值后,另一个变量发生了变化
- 如何在不使用赋值运算符的情况下为动态变量赋值?
- 为什么我不能为变量赋值函数?
- 可视化的c++变量赋值使代码正常工作
- 如何为结构类型变量赋值
- 使用 boost python 从 c++ 为 python 中的类成员变量赋值
- QT变量赋值,<没有这样的值>,SIGSEGV
- C++:为全局类变量赋值
- 从类外部为类中的变量赋值
- 在 c++ 中为字符串变量赋值
- 为类中的私有静态变量赋值
- 使用类为变量赋值 (C++)
- 在编译时为变量赋值
- C ++变量赋值,这是正常的方式吗
- 在C++中为类变量赋值后声明类变量
- 了解工厂方法和静态变量赋值的返回值优化 (Visual Studio)
- 如何在 c++ 中从函数获取返回值而不为其变量赋值
- 简单的引用变量赋值导致对象的全局指针出现segfault