相关疑难解决方法(0)

用变量进行C结构初始化

我遇到了C89之后似乎没有通过任何C标准解决的问题,除非提到结构初始化限制已被解除.但是,我使用Open Watcom IDE(用于调试)遇到错误,其中编译器声明初始化程序必须是常量表达式.

这是正在发生的事情的要点.

typedef struct{
 short x;
 short y;

} POINT;

void foo( short x, short y )
{
 POINT here = { x, y }; /* <-- This is generating the error for the compiler */

 /* ... */

}
Run Code Online (Sandbox Code Playgroud)

任何想法为什么,或什么标准不允许?

c variables structure initialization

3
推荐指数
1
解决办法
5297
查看次数

标签 统计

c ×1

initialization ×1

structure ×1

variables ×1