Error: Incorrect conversion from 'void (*) ()' to 'void (*) ()' - what?

I am trying to pass a callback function from C ++ to OpenGL (C API):

gluQuadricCallback(qobj, GLU_ERROR, errorCallback); 

where errorCallback is a function in a file compiled as C ++ code and declared as

 void errorCallback(); 

The code compiles with g ++ 4.4 on Linux, but gives the following error with mingw32 g ++ 4.4 on Windows:

 ..\glwidget.cpp:172: error: invalid conversion from 'void (*)()' to 'void (*)()' ..\glwidget.cpp:172: error: initializing argument 3 of 'void gluQuadricCallback(GLUquadric*, GLenum, void (*)())' 

Is this some kind of mix problem between C and C ++? How can i solve this?

UPDATE: void GLAPIENTRY errorCallback(); neither compiles :(
.. \ glwidget.cpp: 129: error: expected initializer before 'errorCallback'
Now, he is almost certain that this is a call invocation problem and has nothing to do with C linkage , see comments below Thomas's answer.

UPDATE 2: It seems to me that I just ran into the dirty OpenGL problem regarding GLAPIENTRY , APIENTRY and _GLUfuncptr . Here is a VERY LONG discussion of portability issues:
http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2007-October/003023.html

+6
c ++ c gcc function-pointers opengl
source share
1 answer

If that's all you get for the error, this is a pretty shitty message. This is a challenge with calls.

From my glu.h :

 GLAPI void GLAPIENTRY gluQuadricCallback (GLUquadric* quad, GLenum which, _GLUfuncptr CallBackFunc); 

_GLUfuncptr defined as:

 typedef void (GLAPIENTRYP _GLUfuncptr)(); 

from

 #ifndef GLAPIENTRYP #define GLAPIENTRYP GLAPIENTRY * #endif #ifndef GLAPIENTRY #if defined(_MSC_VER) || defined(__MINGW32__) #define GLAPIENTRY __stdcall #else #define GLAPIENTRY #endif #endif 

This explains the difference between Linux and mingw.

From this, you might think that you need to declare your callback as

 void GLAPIENTRY errorCallback(); 

and a __stdcall will be applied to it when necessary.

However, as Ali points out in the comments below, slapping GLAPIENTRY on a callback signature does not always work. It seems that the GLU 1.3 spec simply indicates that void (*func)() accepted. Since some implementations require, instead of _GLUfuncptr , which includes the GLAPIENTRY requirement, but others do not define GLAPIENTRY at all, there is a portability problem.

A possible workaround might be:

 #ifndef GLAPIENTRY #define GLAPIENTRY #endif 

and declare all callbacks with the GLAPIENTRY macro nonetheless.

+7
source share

All Articles