c - 结构体初始化错误

标签 c

我有两个结构,一个是基本结构,position_3d。另一位是雷。

typedef struct{
float x,y,z;    
} position_3d;

typedef struct{
vector_3d direction;
position_3d startPosition;  
} ray;

我已经实现了一个返回position_3d结构的函数

position_3d getIntersectionPosition(ray r, sphere s){
    position_3d pos; 
    //some code

    pos.x = r.startPosition.x + t*r.direction.x; 
    pos.y = r.startPosition.y + t*r.direction.y; 
    pos.z = r.startPosition.z + t*r.direction.z;  
    return pos; 
}

当我打电话时

position_3d pos = getIntersectionPosition(r, s);

我收到此错误:无效的初始值设定项。我正在使用海湾合作委员会。 编译命令为 gcc prog.c -o prog.out -lm -lGL -lGLU -lglut

我现在真的陷入困境了!有人可以帮忙吗?

最佳答案

是线

position_3d pos = getIntersectionPosition(r, s);

在文件范围(那么这是一个错误,因为初始化器不是常量)或 block 范围(那么它应该工作)?

关于c - 结构体初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566790/

相关文章:

c - libxml xmlNodePtr 到原始 xml 字符串?

c - rand(), srand() 1to1替换使用urandom

c - 传递 C 字符串并将其与本地指针一起使用

c - char * 上的段错误++运算符

java - c 代码可以引发 java 异常吗?

c++ - 编写MPI程序: sum in a the array with two process

c++ - 回声打印实现

python - 使用特定编码从 C 代码运行 python 命令

c++ - Windows 7 64 位 Visual Studio 2013 上的 native cl.exe

c - shell 中的历史功能