c++ function can not call c routine or access c globalvariable. Why?

Laurent R rj45rt at hotmail.com
Thu Mar 23 19:43:37 MST 2006

I used 'extern "C"' in C++ code to include the header file of C, and declare 
the variable in the header file, such as 'extern char g_switch'. And define 
the variable in the correspond .c file, such as 'char g_swith = 1'. Now I 
will access this variable from a C++ file/function. But I got a 
un-initialized value from g_swith variable.


>From: Corey Edwards <tensai at zmonkey.org>
>Reply-To: Provo Linux Users Group Mailing List <plug at plug.org>
>To: plug at plug.org
>Subject: Re: c++ function can not call c routine or access c 
>globalvariable. Why?
>Date: Thu, 23 Mar 2006 18:20:38 -0700
>On Fri, 2006-03-24 at 09:07 +0800, Laurent R wrote:
> > Yes, I compiled both parts of codes with the same compiler. But I did 
> > use extern "c" definition.
>C and C++ link objects differently. By specifying 'extern "C"' you tell
>the C++ compiler to use the C-style for the specified objects. C++ by
>default will mangle the name to allow fancy things like overloading and

><< signature.asc >>

>PLUG: http://plug.org, #utah on irc.freenode.net
>Unsubscribe: http://plug.org/mailman/options/plug
>Don't fear the penguin.

Don't just search. Find. Check out the new MSN Search! 

More information about the PLUG mailing list