Sun Studio 11 "Warning (Anachronism)"

Hello,

Compiling a C++ program using Sun Studio 11 compiler on Solaris, I get warnings like this:

Warning (Anachronism): Using blabla(*)(<params>) to initialize extern "C" blabla(*)(<params>).

For example, this happens passing a callback of type jvmtiHeapObjectCallback to IterateOverHeap (both defined in Sun's jvmti.h):

typedef jvmtiIterationControl (JNICALL *jvmtiHeapObjectCallback)

(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data);

jvmtiError (JNICALL *IterateOverHeap) (jvmtiEnv* env,

jvmtiHeapObjectFilter object_filter,

jvmtiHeapObjectCallback heap_object_callback,

const void* user_data);

What does this warning mean?

I checked that JNICALL is defined in Solaris jni_md.h as empty string, so it seems strange for me that the compiler wants extern "C" here.

The same code compiles with no problems on Solaris with gcc, as well as with Visual Studio on Windows and with gcc on Linux and Mac.

Best regards,

Anton

[1040 byte] By [AntonKatilin] at [2007-11-26 9:34:33]
# 1

This topic is discussed in detail in the C++ Migration Guide, section 3.11 "Pointers to extern C Functions".

http://docs.sun.com/source/819-3689/Ch3.Std.html

As discussed in this section, whether a function pointer is treated as pointer to a C function or to a C++ function depends on details of the declaration.

Sun C++ follows the C++ Standard in treating a pointer to a C++ function as different from a pointer to a C function. The standard allows function calls to be implemented differently for the two kinds of functions. Calling a function via the wrong kind of pointer would fail on a system where the function calling sequence really was different.

The Migration Guide provides details and code examples showing how to eliminate the warnings by making the code correct and portable.

clamage45 at 2007-7-7 0:23:54 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Thank you for your prompt reply.

In the guide, it is said:

"The Sun implementation of C and C++ function linkage is binary-compatible. That is not the case with every C++ implementation, although it is reasonably common".

I believe that for all other platforms that we support - Linux, Mac OS X, Windows - the only difference in C and C++ linkage is C++ name mangling.

I'm not 100% sure (just curious, do you know any implementations where C and C++ functions are not linkage compatible?), but there never were runtime problems with such C/C++ function mixing in our code.

Actually, the mixing happens in our code because we declare class with single static function (callback implemetation) right in the function where function requiring callback parameter is used. This is similar to Java anonymous classes, and helps to write simpler code (especially when callback code is short, and there are many different callbacks in different places of the code):

void qqq() {

// ...

struct Tmp {

static void myCallback() { ... }

};

foo(&Tmp::myCallback);

//

}

So, unfortunately, the offered solutions (wrapping) will not work in our case, unless we simply rewrite our callbacks as regular C functions.

Is there a compiler option (or a pragma) to suppress this warning?

AntonKatilin at 2007-7-7 0:23:54 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
P.S.:> for all other platforms that we support - Linux, Mac OS X, WindowsTo be more precise: gcc on Linux and Mac OS X and MSVC on Windows
AntonKatilin at 2007-7-7 0:23:54 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

Refer to the C++ Users Guide for the options -errtags and -erroff. You use -errtags to find out the "tag" associated with each warning you get, and then you can use -erroff to list the tags of the warnings that you want to suppress.

The compiler emits several warnings about C vs C++ linkage functions, each with a different tag. If you get more than one version of the warning, you will need more than one tag in the -erroff option.

CC -erroff=tag1,tag2,tag3 ...

clamage45 at 2007-7-7 0:23:54 > top of Java-index,Development Tools,Solaris and Linux Development Tools...