Home > Software engineering >  How to pass a variable's pointer?
How to pass a variable's pointer?

Time:06-06

This is my code:

GLint framebuffer_handle = 0;

void glGetIntegerv(GLenum pname,  GLint * data){ ... }

glGetIntegerv(GL_FRAMEBUFFER_BINDING, *framebuffer_handle);  

The last line reports an error:

indirection requires pointer operand ('GLint' (aka 'int') invalid)

What's the problem with this code?

CodePudding user response:

framebuffer_handle is not a pointer, so you can't dereferenced it with the * operator. That is what the compiler is complaining about.

glGetIntegerv() wants a pointer to a GLint. A pointer holds a memory address. You need to use the & operator to get the address of (ie, a pointer to) the framebuffer_handle variable, eg:

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer_handle);  
  •  Tags:  
  • c
  • Related