• 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
Re: Proper use of Header files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper use of Header files


  • Subject: Re: Proper use of Header files
  • From: Howard Moon <email@hidden>
  • Date: Fri, 02 Nov 2012 11:02:57 -0700


On Oct 29, 2012, at 9:59 AM, Jens Alfke wrote:


On Oct 29, 2012, at 8:39 AM, Howard Moon <email@hidden> wrote:

If the header is read by more than one implementation file, the compiler will generate more than one copy of the code, probably causing problems with the linker.

There is no such problem.  Try it and see.  If you're getting multiply-defined symbols, then you've forgotten include guards (or #pragma once).

Huh? Of course this is a problem. I think you must have misread the description (it’s a _linker_ issue, not a compile-time issue.)

This has nothing to do with #include guards. If you have a global symbol defined (not just declared) in a header, then its definition will appear in the object code of every source file that includes that header. If there’s more than one such source file, the linker will complain that the symbol is multiply defined. 

—Jens

Ah, you're talking about GLOBAL symbols.  Ok, then you are correct, that will generate a linker error.  I work almost exclusively with C++ classes, and was thinking of member functions. I had not considered global functions.  And yes, I knew include guards were related to compile-time errors, not link-time errors, but I thought that maybe *you* had gotten mixed up as to the type of error you were expecting.  My apologies.

-Howard


 _______________________________________________
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

  • Prev by Date: Re: Every project reverts to "iOS Device" destination on every open
  • Next by Date: Re: Every project reverts to "iOS Device" destination on every open
  • Previous by thread: Re: How to use Instruments to profile network I/O?
  • Next by thread: Xcode 4.5.x + 10.7 SDK?
  • Index(es):
    • Date
    • Thread