• 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: n00b question about includes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: n00b question about includes


  • Subject: Re: n00b question about includes
  • From: Alastair Houghton <email@hidden>
  • Date: Sat, 11 Aug 2007 10:04:59 +0100

On 11 Aug 2007, at 09:55, Juan Nunez-Iglesias wrote:

Incidentally, I've always been taught to use global const variables
rather than #defines. e.g. instead of

#define FOO 5

write

const double FOO = 5;

That's often a mistake. It doesn't do what you think, in C at least---the above statement declares a *variable*, not a constant. C+ + is different in that respect, which is why people are taught to do this, but in C you can end up with linker errors if you stick something like that in a header (you can, of course, avoid the linker errors by putting "static" on the front, but you've still declared a variable rather than a constant).


#define is fine; if you care about the type, cast it like so:

  #define FOO ((double)5)

For integer constants, anonymous enums are quite handy:

  enum {
    kFoo = 5
  };

Kind regards,

Alastair.

--
http://alastairs-place.net




_______________________________________________

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: n00b question about includes
      • From: Uli Kusterer <email@hidden>
References: 
 >n00b question about includes (From: d2kagw <email@hidden>)
 >Re: n00b question about includes (From: "Juan Nunez-Iglesias" <email@hidden>)

  • Prev by Date: Re: Watching folders for new files and event handling based on that?
  • Next by Date: Re: create subimage from NSBitmapImageRep
  • Previous by thread: Re: n00b question about includes
  • Next by thread: Re: n00b question about includes
  • Index(es):
    • Date
    • Thread