public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* g++ problem when attempting to cast a function pointer in an OpenGL GLU callback
@ 2005-07-20 17:58 Day, Michael A AMRDEC/UAH
  2005-07-20 18:04 ` Brian Dessent
  0 siblings, 1 reply; 2+ messages in thread
From: Day, Michael A AMRDEC/UAH @ 2005-07-20 17:58 UTC (permalink / raw)
  To: cygwin

I've got a program I'm attempting to port from Red Hat Enterprise Linux 3 to Cygwin (on Windows).
 
g++ -v in Cygwin reveals: gcc version 3.4.4
g++ -v in Red Hat reveals: gcc version 3.2.3-52
 
There's the background.  Here's the problem:
 
I'm attempting to cast a function pointer in the following C++ code:
 
------------------------------------------
/* ... includes and what not ... */
 
void tcbBegin(GLenum prim) { 
    cout << "BEGIN"; 
}
 
/* ... */
 
void tessellateTest() {
 //Allocate a new GLU tessellation object
 GLUtesselator *tess = gluNewTess();
 
 //Assigning callbacks
 
 //begin callback
 gluTessCallback(tess,GLU_TESS_BEGIN, (void(*)()) tcbBegin);    // THIS IS LINE 71 //
 
/* ... */
--------------------------------------
 
When compiling, this error happens in Cygwin:
test.cpp:72: error: invalid conversion from `void (*)()' to `void (*)()'
 
No error occurs in Red Hat.  The cast works just fine, and I've used this code with no problem for several months.
 
Not casting at all results in this error (on both Red Hat and Cygwin):
test.cpp:71: error: invalid conversion from `void (*)(GLenum)' to `void (*)()'
 
My compile line in Cygwin looks like:
$ g++ test.cpp -lglu32 -lopengl32
 
And in Red Hat it looks like:
$ g++ test.cpp -lGLU -lGL

Any idea whats going on?  It seems to me that the cast should be legal.  Have the rules changed in g++ between the two versions? I have already tried using a reinterpret_cast, but that didn't work.
 
Thanks,
 
Mike Day
Virtual Targets Center
https://modelexchange.army.mil/
 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: g++ problem when attempting to cast a function pointer in an OpenGL   GLU callback
  2005-07-20 17:58 g++ problem when attempting to cast a function pointer in an OpenGL GLU callback Day, Michael A AMRDEC/UAH
@ 2005-07-20 18:04 ` Brian Dessent
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Dessent @ 2005-07-20 18:04 UTC (permalink / raw)
  To: cygwin

"Day, Michael A AMRDEC/UAH" wrote:

> test.cpp:72: error: invalid conversion from `void (*)()' to `void (*)()'

Win32 API functions generally use the stdcall calling convention, not
the standard C one.  Your tcbBegin is not defined this way and this
could be what the compiler is trying to tell you, although the error
certainly isn't very clear.

If you look at glu.h:

GLAPI void APIENTRY gluTessCallback (GLUtesselator* tess, GLenum which,
_GLUfuncptr CallBackFunc);

where _GLUfuncptr is defined as:

typedef void (APIENTRY *_GLUfuncptr)();

where APIENTRY expands to "__attribute__ ((__stdcall__))".  So you'll
need to declare your callback with that attribute or else it will not
work.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-20 17:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-20 17:58 g++ problem when attempting to cast a function pointer in an OpenGL GLU callback Day, Michael A AMRDEC/UAH
2005-07-20 18:04 ` Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).