Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Error: Using static_cast to convert from int to extern "C"

807736Nov 20 2008 — edited Nov 21 2008
hello all,
following my precedent post http://forums.sun.com/thread.jspa?threadID=5349240, i have this error:
line 267: Error: Using static_cast to convert from int to extern "C"
void(*)() not allowed.

and the line 267 contains:
266 #ifdef VTK_USE_GLX_GET_PROC_ADDRESS_ARB
267 return
static_cast<vtkOpenGLExtensionManagerFunctionPointer>(glXGetProcAddressARB(reinterpret_cast<const
GLubyte *>(fname)));
268 #endif //VTK_USE_GLX_GET_PROC_ADDRESS_ARB


This is related to Paraview that needs OpenGl libs (or Mesa), and in glx.h, there is:
#ifdef __cplusplus
extern "C" {
#endif
...
typedef void (*__GLXextFuncPtr)(void);
extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);

Compiling with g++ from pkg:/SUNWgcc@3.4.3-0.101, the problem never appears, it's only related to use of sunstudio, as i said in my previous post.
I already asked on paraview mailing lists, but got no answer so far.

Thanks,

gerard

Comments

807575
There is not enough data yet for me to tell whether this is a Sun Studio compiler bug, invalid code that happens to be accepted by g++, or something else.

Please show the declarations for
vtkOpenGLExtensionManagerFunctionPointer
__GLXextFuncPtr
GLubyte
fname
807736
clamage45 wrote:
There is not enough data yet for me to tell whether this is a Sun Studio compiler bug, invalid code that happens to be accepted by g++, or something else.
as i already said, i'm a dev, i only get the tarball here:
http://www.paraview.org/files/v3.4/paraview-3.4.0.tar.gz

to reply to you as fast as possible, the complete log is available here:
http://www.latp.univ-mrs.fr/~henry/Solaris/x86/MAKE6.LOG

the file concerned is ./ParaView-3.4.0/VTK/Rendering/vtkOpenGLExtensionManager.cxx

i'm unable to give you a short example to highlight the behaviour of sunstudio.

thanks for your help,

gerard
807575
I can't debug large applications like this for you. I can evaluate compiler bugs.

I tried the compilation line that failed, substituting the path where I unpacked ParaView for your path, but some files come up missing.

Please run the CC command that failed, but substitute -E for the -c option, and redirect all output into a file. Example:
CC <options> vtkOpenGLExtensionManager.cxx -E >& vtkOpenGLExtensionManager.i
Move the .i file to a an empty directory, and try to compile it as
CC -c vtkOpenGLExtensionManager.i
You should see the same error messages. If so, post your email address here, and I'll tell you where to send the file.
807736
here are what i obtain:
henry@ultra20:/tmp/toot$ CC -c vtkOpenGLExtensionManager.i
"vtkOpenGLExtensionManager.h", line 140: Error: In this declaration "vtkOpenGLExtensionManager" is of an incomplete type "VTK_RENDERING_EXPORT".
"vtkOpenGLExtensionManager.h", line 140: Error: "," expected instead of ":".
"vtkOpenGLExtensionManager.h", line 144: Error: vtkOpenGLExtensionManager, of type int, was previously declared VTK_RENDERING_EXPORT.
"vtkOpenGLExtensionManager.h", line 144: Error: Multiple declaration for vtkOpenGLExtensionManager.
"vtkOpenGLExtensionManager.h", line 144: Error: "," expected instead of "*".
"vtkOpenGLExtensionManager.h", line 145: Error: ostream is not defined.
"vtkOpenGLExtensionManager.h", line 151: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 155: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 160: Error: ExtensionsString is not defined.
"vtkOpenGLExtensionManager.h", line 164: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 170: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 179: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 187: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 257: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 259: Error: A declaration was expected instead of "protected".
"vtkOpenGLExtensionManager.h", line 260: Error: Multiple declaration for vtkOpenGLExtensionManager.
"vtkOpenGLExtensionManager.h", line 261: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 261: Error: Type name expected instead of "vtkOpenGLExtensionManager".
"vtkOpenGLExtensionManager.h", line 261: Error: Illegal number of arguments for ~file level().
"vtkOpenGLExtensionManager.h", line 263: Error: Template vtkWeakPointer is not defined.
"vtkOpenGLExtensionManager.h", line 268: Error: vtkTimeStamp is not defined.
"vtkOpenGLExtensionManager.h", line 270: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 277: Error: "virtual" is not allowed here.
"vtkOpenGLExtensionManager.h", line 279: Error: A declaration was expected instead of "private".
"vtkOpenGLExtensionManager.h", line 280: Error: ")" expected instead of "&".
Compilation aborted, too many Error messages.
my email is ghenry_at_cmi.univ-mrs.fr

thanks for your help,

gerard
807575
I'm taking this discussion off line for now.
807575
Here are the results of my investigation.

The code in ParaView is actually invalid, but is accepted by g++.

The code in question when stripped down looks like this:
typedef unsigned char GLubyte;

typedef void ( * __GLXextFuncPtr ) ( void ) ; // implicitly extern "C++"
extern "C" {
typedef void ( * vtkOpenGLExtensionManagerFunctionPointer ) ( void ) ;
}

extern "C"
__GLXextFuncPtr  vtkglX :: glXGetProcAddressARB ( const GLubyte * ) ;


vtkOpenGLExtensionManagerFunctionPointer
vtkOpenGLExtensionManager :: GetProcAddress ( const char * fname )
{
    // ...
    return static_cast < vtkOpenGLExtensionManagerFunctionPointer >
    ( glXGetProcAddressARB( reinterpret_cast< const GLubyte* > (fname) ) ) ;
}
This code fragment is not compilable since some declarations are missing, but it shows the error.

In the return statement, the return value of glXGetProcAddressARB is converted via a static cast to type vtkOpenGLExtensionManagerFunctionPointer. The problem is that glXGetProcAddressARB returns a pointer to an extern "C++" function, but type vtkOpenGLExtensionManagerFunctionPointer is a pointer to an extern "C" function. The two function kinds are not compatible.

g++ incorrectly allows the conversion via a static_cast. Sun C++ and another compiler I tried do not allow it.

The simplest fix is to change the static_cast to a reinterpret_cast, which allows this kind of pointer conversion.

But on a system where C and C++ functions have different calling sequences, the code would not run correctly even if it compiled. I do not know of any such systems currently, but I would not be surprised to see some.

The correct fix is to match up the C and C++ function types, or to use proxy functions to convert between C and C++ function declarations. The C++ Migration Guide in section 3.11 discusses this topic in detail, with examples.
http://docs.sun.com/source/819-3689/Ch3.Std.html#pgfId-18041
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 19 2008
Added on Nov 20 2008
6 comments
499 views