Re: n00b question about includes
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