Discussion:
Warning on Sun/C++
(too old to reply)
s***@gmail.com
2004-10-07 22:38:44 UTC
Permalink
I was having trouble since long time removing some of the warnings
from my file which was builted on Solaris 9 using C++ compiler 5.0.3.

Your help would be highly appreciated.
Warning message is :

Warning (Anachronism): Formal argument destroy_value_func of type
extern "C" void(*)(Void *) in call to g_hash_table(extern "C" unsigned
(*)(const void*),extern "C" int(*)(const void*,const void*),extern "C"
void (*)(void*),extern "C" void (*)(void*)) is being passed
void(*)(void*).

This kind of several warnings I am getting.

Thanks,
Seongbae Park
2004-10-07 23:01:56 UTC
Permalink
Post by s***@gmail.com
I was having trouble since long time removing some of the warnings
from my file which was builted on Solaris 9 using C++ compiler 5.0.3.
Your help would be highly appreciated.
A slight reformating of the error message makes it a bit more clearer:

Warning (Anachronism): Formal argument destroy_value_func of type
extern "C" void(*)(Void *)
in call to
g_hash_table(
extern "C" unsigned (*)(const void*),
extern "C" int(*)(const void*,const void*),
extern "C" void (*)(void*),
extern "C" void (*)(void*))
is being passed
void(*)(void*).
Post by s***@gmail.com
This kind of several warnings I am getting.
Thanks,
Apparently, you have a function called g_hash_table, whose third and fourth
parameters are c-linkage (extern "C") function pointers
whereas you're passing a regular c++ function as one of those parameters.

The fix is to pass a pointer to a C linkage function.
This may involve changing the actual function to be extern "C"
as well as changing a local variable of the function pointer
to be extern "C".

Following is an example:

extern "C" int myfunc(void) { return 0; }

extern "C" {
typedef int (*myfunc_t)(void);
};

int testfunc( myfunc_t t);

void test(void) {
myfunc_t ptr = myfunc;
testfunc(ptr);
}

This will compile without warning. If you get rid of extern "C"
from the myfunc definition, you'll see the similar warning.
If you need to have a pointer variable to a function that's c-linkage
(like "ptr" above), you'll need to use typedef.

This affects, among others, the name mangling of those functions.
The names of extern "C" delcared functions won't get mangled.
Other than that, C linkage and C++ linkage have been compatible so far
on most platforms including Sun, so it usually works just fine.
But there's no guarantee that this won't change in the future.
--
#pragma ident "Seongbae Park, compiler, http://blogs.sun.com/seongbae/"
Christian
2004-10-08 06:02:16 UTC
Permalink
Post by s***@gmail.com
I was having trouble since long time removing some of the warnings
from my file which was builted on Solaris 9 using C++ compiler 5.0.3.
Don't want to spread FUD, but IIRC 5.0 was not the best version of the
Sun compiler, compared to 5.2 and later at least (not that this should
have anything to do with your problem however).
Post by s***@gmail.com
Your help would be highly appreciated.
Warning (Anachronism): Formal argument destroy_value_func of type
extern "C" void(*)(Void *) in call to g_hash_table(extern "C" unsigned
(*)(const void*),extern "C" int(*)(const void*,const void*),extern "C"
void (*)(void*),extern "C" void (*)(void*)) is being passed
void(*)(void*).
Assuming that you are actually using the C++ compiler "CC" (not the C
compiler "cc") and that the g_hash_table() function is a C function
(in a C library), add 'extern "C"' to the declaration of your
"destroy_value_func" version's prototype.

For more information you might want to google for "c c++ linkage".

Cheers,
Christian

Loading...