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.

Why?

From: Corey Edwards <[EMAIL PROTECTED]>
Reply-To: Provo Linux Users Group Mailing List <[email protected]>
To: [email protected]
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 not
> 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
namespaces.

Corey



<< 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! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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

Reply via email to