0

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

5
  • The data type of shape is int. Commented Apr 10, 2016 at 10:29
  • 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. Commented Apr 10, 2016 at 10:42
  • @JoachimPileborg, added. Commented Apr 10, 2016 at 10:53
  • 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. Commented Apr 10, 2016 at 11:00
  • to start, there are two different parameters to the function: drawVertex() that are both named `shape' Commented Apr 10, 2016 at 18:35

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

nothing of what you mentionned I think. The complete code: dpaste.com/3RN0KR6
@J.Doe How can you write shape[i][j] and at the same time write int shape.
OMG! didn t see that, had been searching for soo long!
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.