• 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: Circular references
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Circular references


  • Subject: Re: Circular references
  • From: Jay Reynolds Freeman <email@hidden>
  • Date: Sun, 13 Sep 2009 15:31:16 -0700

A classic (but non-traditionally-Cocoa) way to deal with this problem is with #ifndef preprocessor statements. You make up a preprocessor symbol for each include file -- I often use the include-file name in all capitals, with some "__"s bracketing it. Then you use it as follows. Suppose you have a header file called "foo.h" with some simple stuff in it. Here is what the text of "foo.h" might be:

######## SNIP ########

// foo.h, copyright whoever whenever

#ifndef __FOO_H__
#define __FOO_H__

#import bar.h
#import baz.h

extern int whatever();

// ... more statements to your liking.

#endif

######## SNIP ########

This mechanism ensures that the statements inside the #ifndef ... #endif will be included only once in any file that goes through the preprocessor.

--  Jay Reynolds Freeman
---------------------
email@hidden
http://web.mac.com/jay_reynolds_freeman (personal web site)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Circular references
      • From: Kyle Sluder <email@hidden>
References: 
 >Circular references (From: DKJ <email@hidden>)

  • Prev by Date: Re: Circular references
  • Next by Date: Re: Circular references
  • Previous by thread: Re: Circular references
  • Next by thread: Re: Circular references
  • Index(es):
    • Date
    • Thread