简体   繁体   中英

C - subscripted value is neither array nor pointer nor vector

I declared an array and pass a 2D array as a parameter. However I keep getting the same error: subscripted value is neither array nor pointer nor vector. for this line: vertex[i][j-1] = shape[i][j];

How can I solve it?

header file:

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

function call:

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]);
    }

}

EDIT:

the complete compiler output:

cc -c -o mijnTest.o mijnTest.c

mijnTest.c:23:59: error: conflicting types for 'shape'

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

mijnTest.c:23:25: note: previous definition of 'shape' was here

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

mijnTest.c: In function 'drawVertex':

mijnTest.c:43:26: error: subscripted value is neither array nor pointer nor vector

vertex[i][j-1] = shape[i][j]; ^

mijnTest.c: In function 'drawScene':

mijnTest.c:69:2: warning: passing argument 1 of 'drawVertex' from incompatible pointer type [enabled by default]

drawVertex(assen,6,0); ^

mijnTest.c:23:6: note: expected 'GLfloat ( )[4]' but argument is of type 'GLfloat ( )[3]'

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

make: *** [mijnTest.o] Error 1

A declaration like

GLfloat vertex[][3]

is only valid as a function argument (and then it's equal to GLfloat (*vertex)[3] ). If you declare an array as a local or global variable, you must give it a size.

It works when you define mijnplayer because then the compiler can deduce the size from the data you use for initialization (the size is set implicitly). If you don't do it then the compiler can't know what size the array is, and you need to specify it explicitly.

Its because shape is an variable of data type int and its neither array nor pointer nor vector.

Either you got the data type wrong or you are just using the wrong variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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