0
votes

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

2
The data type of shape is int. - Sumeet
Can you please edit your question to include the complete output from the compiler, in full and unedited, and including any possible informational notes and warnings. - Some programmer dude
@JoachimPileborg, added. - J.Doe
When reading error messages, always start at the top. In your case you have mijnTest.c:23:59: error: conflicting types for ‘shape’. That should lead you to take a close look at the function declaration and its arguments. - Some programmer dude
to start, there are two different parameters to the function: drawVertex() that are both named `shape' - user3629249

2 Answers

1
votes

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.

1
votes

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.