Re: What is the default type for an integer literal (as relates to its use in NSLog)?
Re: What is the default type for an integer literal (as relates to its use in NSLog)?
- Subject: Re: What is the default type for an integer literal (as relates to its use in NSLog)?
- From: Stuart Malin <email@hidden>
- Date: Mon, 15 Dec 2008 11:06:52 -1000
On Dec 15, 2008, at 10:50 AM, Nick Zitzmann wrote:
On Dec 15, 2008, at 1:39 PM, Stuart Malin wrote:
and define a method that takes the option as a parameter
- (void) someMethodWithOption:(MyOptionValue)optionVlaue;
Question: Should I force MyOptionValue to be an NSUInteger? If so,
how would I achieve that? (Sorry, my C is weak).
It depends. On one hand, I see no reason not to just keep that 32-
bit (unless you have a very good reason), but if you do so, and you
pass in, say, menu tags, then you'll have to cast the return value
or else that warning I mentioned earlier will sound. OTOH, you won't
have to cast anything if you make it an NSInteger typedef, but you
do lose the warning that would normally appear if not all cases are
handled in a switch. So which is more important to you?
If you want to make an NS(U)Integer typedef, then you do what Apple
does:
enum
{
YOBlahBlah = 0,
YOBlahBlah2
};
typedef NSUInteger YourOptions;
Yes, but then I lose the compile-time enforcement that only defined
values are supplied (as is achieved with typedef enum). So, as you
suggest, I see no reason not to leave as 32-bit. Yet Apple doesn't...
is there an advantage to their approach (other than the type being
unsigned)?
_______________________________________________
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