• 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: Mon, 29 Oct 2012 08:39:44 -0700

On Oct 28, 2012, at 11:49 AM, David Rowland 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).

The main reason for not putting all your code in headers is to keep compile times down, (when using incremental builds).  If you change any code in the header, then all files in which that header is included must be recompiled.  For small enough projects, or if not using incremental builds, that's really irrelevant.

Another reason is readability, because it's a lot easier to visually scan a header for function names (and associated comments) then it is to attempt that with a complete implementation file with all its code defined, especially in larger classes. (I think it makes doxygen output easier to work with, too.)

It also allows you to have "circular" dependencies, because you can forward-declare a co-dependent class in the header, and only include its header in the implementation file.  Otherwise, your implementation code in each class would be attempting to include the implementation code of the other class, which would int turn attempt to include the first class' implementation code, etc..

As you mentioned, templates require that the implementation details be there in the header.  So it can't be illegal or improper to do.

Personally, I do it the way my company management tells me to do it, unless I can convince them that I have a better way. :-)

-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

  • Follow-Ups:
    • Re: Proper use of Header files
      • From: Jens Alfke <email@hidden>
References: 
 >Proper use of Header files (From: koko <email@hidden>)
 >Re: Proper use of Header files (From: David Rowland <email@hidden>)

  • Prev by Date: Re: Automatic provisioning profile selector
  • Next by Date: Re: How to make a path relative to the current Xcode application?
  • Previous by thread: Re: Proper use of Header files
  • Next by thread: Re: Proper use of Header files
  • Index(es):
    • Date
    • Thread