• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
extern "C" and global variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

extern "C" and global variables


  • Subject: extern "C" and global variables
  • From: John Weeks <email@hidden>
  • Date: Fri, 31 Mar 2006 15:13:04 -0800

Hi, folks.

I have a C++ source file that defines a global variable:

extern "C" unsigned char gSuppressLiveUpdate = 0;

so that it can be used from a C source file. In the C file, of course, I have

extern unsigned char gSuppressLiveUpdate;

gcc complains (OK, it's just a warning):

warning: 'gSuppressLiveUpdate' initialized and declared 'extern'

I guess I see the point of the warning; it's not really extern because it
is being defined right there. But then, how do I prevent name mangling so
that it can be used in the C file, without using the "extern" keyword?

At the moment I have suppressed the warning by defining and initializing it
in the C file and using just extern "C" unsigned char gSuppressLiveUpdate;
in the C++ file. But that's not satisfying; I want to be able to put the
definition where I want it.

CodeWarrior and VC++.net are both OK with this, but I realize that gcc is
actually more standards-compliant that they are. I tried searching for an
answer with Google, but all the discussions are about functions declared
extern "C".

Regards,
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax   (503) 620-6754
email   email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: extern "C" and global variables
      • From: Rush Manbert <email@hidden>
  • Prev by Date: Re: Variable view and Unions
  • Next by Date: Re: Xcode 2.2.1 precomp link warning -> still happening
  • Previous by thread: Re: Xcode 2.2.1 precomp link warning -> still happening
  • Next by thread: Re: extern "C" and global variables
  • Index(es):
    • Date
    • Thread