Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Leda > Re: Warning on ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 165 of 212
Post > Topic >>

Re: Warning on Sun/C++

by Seongbae Park <Seongbae.Park@[EMAIL PROTECTED] > Oct 7, 2004 at 11:01 PM

swapnil.palod@[EMAIL PROTECTED]
 <swapnil.palod@[EMAIL PROTECTED]
> wrote:
> 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 :
> 

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*).

> 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/"
 




 3 Posts in Topic:
Warning on Sun/C++
swapnil.palod@[EMAIL PROT  2004-10-07 15:38:44 
Re: Warning on Sun/C++
Seongbae Park <Seongba  2004-10-07 23:01:56 
Re: Warning on Sun/C++
cklutz@[EMAIL PROTECTED]   2004-10-07 23:02:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 15:22:47 CDT 2008.