【问题标题】:Another "x" does not name a type error另一个“x”没有命名类型错误
【发布时间】:2012-03-27 02:16:48
【问题描述】:

不像很多其他的'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

既然 stack 已经被声明为一个指向 matrix_unit 结构的指针栈,这不应该是有效的吗?

当我使用“gcc -c 3D.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

提前感谢您的帮助。

【问题讨论】:

  • 使用 gcc 4.6.2 编译良好​​span>
  • 嗯.. 我从 C++ 文件中包含在内。这应该有什么影响吗?我正在用 g++ 编译它
  • 用 g++ 4.6.2 编译也很好。所以这不是这个子集的编译器问题。但是我只能测试您在帖子中写的内容。
  • 我应该发布更多代码吗?此文件包含在 cpp 文件中,但我不确定其他任何内容会如何影响它。
  • 我在 ubuntu 上运行 g++ 4.5.2。

标签: c


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-09
    • 2011-12-10
    • 1970-01-01
    • 2013-09-09
    • 2015-12-01
    • 2014-12-16
    • 2016-09-25
    • 1970-01-01
    相关资源
    最近更新 更多