Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 另一个";x";不命名类型错误_C - Fatal编程技术网

C 另一个";x";不命名类型错误

C 另一个";x";不命名类型错误,c,C,不像很多其他的“x”在这里没有命名类型错误,我不认为这一个涉及循环依赖,但我仍然很难找到它 typedef struct /* structure definitions */ { float mat[4][4]; } matrix_unit; matrix_unit I = { { 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1 }, }; matrix_unit *stack

不像很多其他的“x”在这里没有命名类型错误,我不认为这一个涉及循环依赖,但我仍然很难找到它

typedef struct        /* structure definitions */
{
   float  mat[4][4];
}  matrix_unit;

matrix_unit I = {
{ 1., 0., 0., 0.,
  0., 1., 0., 0.,
  0., 0., 1., 0.,
  0., 0., 0., 1  },
};

matrix_unit *stack[50];    /* (line 456) array of pointers to act as a stack */
matrix_unit stackbase = I;
stack[0] = &stackbase;  // 'stack' does not name a type
既然堆栈已经声明为指向矩阵单元结构的指针堆栈,这难道不是有效的吗

当我用“gcc-c3d.c”编译代码时,我从这些行中得到以下错误:

3D.c:457:1: error: initializer element is not constant
3D.c:458:1: warning: data definition has no type or storage class
3D.c:458:1: error: conflicting types for ‘stack’
3D.c:456:14: note: previous declaration of ‘stack’ was here
3D.c:458:1: error: invalid initializer

提前感谢您的帮助。

编译器正在尝试将第458行解析为声明。这不是,这是一个声明。语句必须写入函数内部。像这样:

void initialize() 
{
    stack[0] = &stackbase;
}

使用GCC4.6.2Hmm编译很好。。我从一个C++文件中包含。这会有什么影响吗?我是用g++编译的,也可以用g++4.6.2编译。所以这不是这个子集的编译器问题。然而,我只能测试你在文章中写的东西。我应该发布更多的代码吗?这个文件包含在一个cpp文件中,但我不确定其他任何东西会如何影响它。我正在ubuntu上运行g++4.5.2。