繁体   English   中英

C-下标值既不是数组,也不是指针,也不是向量

[英]C - subscripted value is neither array nor pointer nor vector

我声明了一个数组并将2D数组作为参数传递。 但是我仍然遇到相同的错误:下标值既不是数组,也不是指针,也不是矢量。 对于这条线:vertex [i] [j-1] = shape [i] [j];

我该如何解决?

头文件:

GLfloat mijnplayer [][4] ={
{0,-0.091057,0.198079,0.084590},
{0,-0.158043,0.158043,0.071039},
{0,-0.071039,0.158043,0.158043}};

函数调用:

int main(void)
{   

drawVertex(mijnplayer,3,1);

}

void drawVertex(GLfloat shape[][4], int numberVertex, int shape)
{
    int i,j;
    GLfloat vertex[][3]={0};


    //convert 4element array to 3 element array
    for(i=0;i<numberVertex;i++)
    {
        for(j=1;j<4;j++)
        {
            vertex[i][j-1] = shape[i][j];
        }

    }

    for(i=0;i<numberVertex;i++)
    {

        glVertex3fv(vertex[i]);
    }

}

编辑:

完整的编译器输出:

cc -c -o mijnTest.o mijnTest.c

mijnTest.c:23:59:错误:“形状”的类型冲突

void drawVertex(GLfloat shape [] [4],int numberVertex,int shape)^

mijnTest.c:23:25:注意:先前对“形状”的定义在这里

void drawVertex(GLfloat shape [] [4],int numberVertex,int shape)^

mijnTest.c:在函数'drawVertex'中:

mijnTest.c:43:26:错误:下标值既不是数组也不是指针也不是矢量

顶点[i] [j-1] =形状[i] [j]; ^

mijnTest.c:在函数'drawScene'中:

mijnTest.c:69:2:警告:从不兼容的指针类型传递“ drawVertex”的参数1 [默认启用]

drawVertex(assen,6,0); ^

mijnTest.c:23:6:注意:预期为'GLfloat( )[4]',但参数的类型为'GLfloat( )[3]'

void drawVertex(GLfloat shape [] [4],int numberVertex,int shape)^

make:*** [mijnTest.o]错误1

像这样的声明

GLfloat vertex[][3]

仅作为函数参数有效(然后等于GLfloat (*vertex)[3] )。 如果将数组声明为局部变量或全局变量,则必须为其指定大小。

它在定义mijnplayermijnplayer因为编译器可以从用于初始化的数据中推断出大小(大小是隐式设置的)。 如果不这样做,则编译器将无法知道数组的大小,因此需要明确指定它。

这是因为shape是数据类型int的变量, 它既不是数组,也不是指针,也不是向量。

要么数据类型错误,要么使用的变量错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM