Fixed warnings on Linux where GCC under padantic complained ISO C casting wasn't...
authorRcmaniac25 <rcmaniac25@hotmail.com>
Fri, 21 Jul 2017 15:13:44 +0000 (15:13 +0000)
committerDiederick Niehorster <dcnieho@gmail.com>
Fri, 21 Jul 2017 15:13:44 +0000 (15:13 +0000)
(cherry picked from commit 13ed05fe8d5a9914300b4a9b8175e5c7636125eb)

git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1833 7f0cb862-5218-0410-a997-914c9d46530a

src/fg_callback_macros.h
src/fg_callbacks.c
src/fg_init.c
src/fg_menu.c

index 76d76b1..274b133 100644 (file)
@@ -203,39 +203,39 @@ do                                                                        \
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG0(a,b)                              \
 static void fgh##a##FuncCallback( FGCBUserData userData )                 \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback();                                                           \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)();                                                        \
 }
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG1(a,b)                              \
 static void fgh##a##FuncCallback( int arg1val, FGCBUserData userData )    \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback( arg1val );                                                  \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)( arg1val );                                               \
 }
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG2(a,b)                              \
 static void fgh##a##FuncCallback( int arg1val, int arg2val, FGCBUserData userData ) \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback( arg1val, arg2val );                                         \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)( arg1val, arg2val );                                      \
 }
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG3_USER(a,b,arg1,arg2,arg3)          \
 static void fgh##a##FuncCallback( arg1 arg1val, arg2 arg2val, arg3 arg3val, FGCBUserData userData ) \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback( arg1val, arg2val, arg3val );                                \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)( arg1val, arg2val, arg3val );                             \
 }
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG3(a,b) IMPLEMENT_CALLBACK_FUNC_CB_ARG3_USER(a,b,int,int,int)
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG4(a,b)                              \
 static void fgh##a##FuncCallback( int arg1val, int arg2val, int arg3val, int arg4val, FGCBUserData userData ) \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback( arg1val, arg2val, arg3val, arg4val );                       \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)( arg1val, arg2val, arg3val, arg4val );                    \
 }
 #define IMPLEMENT_CALLBACK_FUNC_CB_ARG5(a,b)                              \
 static void fgh##a##FuncCallback( int arg1val, int arg2val, int arg3val, int arg4val, int arg5val, FGCBUserData userData ) \
 {                                                                         \
-    FGCB##b callback = (FGCB##b)userData;                                 \
-    callback( arg1val, arg2val, arg3val, arg4val, arg5val );              \
+    FGCB##b* callback = (FGCB##b*)&userData;                              \
+    (*callback)( arg1val, arg2val, arg3val, arg4val, arg5val );           \
 }
 
 /*
@@ -252,7 +252,10 @@ void FGAPIENTRY glut##a##Func( FGCB##b callback )                         \
 {                                                                         \
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glut"#a"Func" );                  \
     if( callback )                                                        \
-        glut##a##FuncUcall( fgh##a##FuncCallback, (FGCBUserData)callback ); \
+    {                                                                     \
+        FGCB##b* reference = &callback;                                   \
+        glut##a##FuncUcall( fgh##a##FuncCallback, *((FGCBUserData*)reference) ); \
+    }                                                                     \
     else                                                                  \
         glut##a##FuncUcall( NULL, NULL );                                 \
 }
index 0e656a8..182fe2e 100644 (file)
@@ -83,7 +83,10 @@ void FGAPIENTRY glutTimerFunc( unsigned int timeOut, FGCBTimer callback, int tim
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutTimerFunc" );
     if( callback )
-        glutTimerFuncUcall( timeOut, fghTimerFuncCallback, timerID, (FGCBUserData)callback );
+    {
+        FGCBTimer* reference = &callback;
+        glutTimerFuncUcall( timeOut, fghTimerFuncCallback, timerID, *((FGCBUserData*)reference) );
+    }
     else
         glutTimerFuncUcall( timeOut, NULL, timerID, NULL );
 }
@@ -270,15 +273,18 @@ void FGAPIENTRY glutJoystickFuncUcall( FGCBJoystickUC callback, int pollInterval
 
 static void fghJoystickFuncCallback( unsigned int buttons, int axis0, int axis1, int axis2, FGCBUserData userData )
 {
-    FGCBJoystick callback = (FGCBJoystick)userData;
-    callback( buttons, axis0, axis1, axis2 );
+    FGCBJoystick* callback = (FGCBJoystick*)&userData;
+    (*callback)( buttons, axis0, axis1, axis2 );
 }
 
 void FGAPIENTRY glutJoystickFunc( FGCBJoystick callback, int pollInterval )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutJoystickFunc" );
     if( callback )
-        glutJoystickFuncUcall( fghJoystickFuncCallback, pollInterval, (FGCBUserData)callback );
+    {
+        FGCBJoystick* reference = &callback;
+        glutJoystickFuncUcall( fghJoystickFuncCallback, pollInterval, *((FGCBUserData*)reference) );
+    }
     else
         glutJoystickFuncUcall( NULL, pollInterval, NULL );
 }
index ed29a83..b8a38f7 100644 (file)
@@ -683,15 +683,16 @@ void FGAPIENTRY glutInitErrorFuncUcall( FGErrorUC callback, FGCBUserData userDat
 
 static void fghInitErrorFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
 {
-    FGError callback = (FGError)userData;
-    callback( fmt, ap );
+    FGError* callback = (FGError*)&userData;
+    (*callback)( fmt, ap );
 }
 
 void FGAPIENTRY glutInitErrorFunc( FGError callback )
 {
     if (callback)
     {
-        glutInitErrorFuncUcall( fghInitErrorFuncCallback, (FGCBUserData)callback );
+        FGError* reference = &callback;
+        glutInitErrorFuncUcall( fghInitErrorFuncCallback, *((FGCBUserData*)reference) );
     }
     else
     {
@@ -711,15 +712,16 @@ void FGAPIENTRY glutInitWarningFuncUcall( FGWarningUC callback, FGCBUserData use
 
 static void fghInitWarningFuncCallback( const char *fmt, va_list ap, FGCBUserData userData )
 {
-    FGWarning callback = (FGWarning)userData;
-    callback( fmt, ap );
+    FGWarning* callback = (FGWarning*)&userData;
+    (*callback)( fmt, ap );
 }
 
 void FGAPIENTRY glutInitWarningFunc( FGWarning callback )
 {
     if (callback)
     {
-        glutInitWarningFuncUcall( fghInitWarningFuncCallback, (FGCBUserData)callback );
+        FGWarning* reference = &callback;
+        glutInitWarningFuncUcall( fghInitWarningFuncCallback, *((FGCBUserData*)reference) );
     }
     else
     {
index ae7405c..daad294 100644 (file)
@@ -795,18 +795,19 @@ int FGAPIENTRY glutCreateMenuUcall( FGCBMenuUC callback, FGCBUserData userData )
 /* Standard glutCreateMenu */
 static void fghCreateMenuCallback( int menu, FGCBUserData userData )
 {
-    FGCBMenu callback = (FGCBMenu)userData;
-    callback( menu );
+    FGCBMenu* callback = (FGCBMenu*)&userData;
+    (*callback)( menu );
 }
 
 int FGAPIENTRY glutCreateMenu( FGCBMenu callback )
 {
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutCreateMenu" );
     if (!callback)
-       {
+    {
         return glutCreateMenuUcall( NULL, NULL );
-       }
-    return glutCreateMenuUcall( fghCreateMenuCallback, (FGCBUserData)callback );
+    }
+    FGCBMenu* reference = &callback;
+    return glutCreateMenuUcall( fghCreateMenuCallback, *((FGCBUserData*)reference) );
 }
 
 /*