167
|
tomlogic · 技术社区 · 14 年前 |
1
293
在C语言中,具有静态存储持续时间的对象必须用 常量表达式 ,或使用包含常量表达式的聚合初始值设定项。
“大”对象在C中永远不是常量表达式,即使该对象被声明为
此外,在C语言中,“常量”一词是指
文字常量
(就像
例如,这是 常数
您将得到相同的错误:尝试用非常量初始化静态对象。
|
2
78
这是语言的局限。在第6.7.8/4节中:
在第6.6节中,规范定义了必须视为常量表达式的内容。不,它在哪里声明常量变量必须被视为常量表达式。编译器对此进行扩展是合法的(
如果你能改变
|
3
5
http://www.geeksforgeeks.org/g-fact-80/ 代码在gcc中失败并在g中传递++ /
|
4
2
|
5
2
2021年:谁因为
在gccv8.1+中,支持嵌套常量初始值设定项,下面的代码将被编译。
有关更多信息,请参见以下内容:
|
6
0
gcc 7.4.0不能编译如下代码:
常量字符*str2=str1;
函数名当然是一个编译时常量。所以这段代码可以工作:
|
7
-2
解决办法是把它改成这样
编译器将内存中的一个位置分配给一个变量。第二种方法是尝试将第二个变量赋给与第一个变量相同的位置,这是没有意义的。使用宏预处理器解决了这个问题。 |
Tom Buck · c#程序在整数列表上冻结 6 年前 |
Ran Lavi · 在c中初始化结构的指针++ 6 年前 |
Js_zero · 在c++中实例化对象有几种方法,它们之间有什么区别 6 年前 |
jfernal · 节点。js在加载其他函数之前等待初始化变量 6 年前 |
Victor · 在javafx中运行时更改标签文本 6 年前 |
blubb · 在Kotlin中是否有更惯用的方法来初始化此映射? 6 年前 |
Bing Bang · 初始化包含字节数组的结构数组 6 年前 |