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: "Michael Ash" <email@hidden>
- Date: Mon, 15 Dec 2008 14:58:19 -0500
On Mon, Dec 15, 2008 at 2:35 PM, Stuart Malin <email@hidden> wrote:
> I am trying to be 32/64 bit "clean" in some new code that I am writing. When
> I declare some integer values, say for named option values as shown here,
> what is the type that the compiler assigns to these values?
>
> enum {
> SomeOptionValue = 1,
> AnotherOptionValue = 2,
> };
>From reading the summaries in a google search for "c enum type", it
would appear that they are of type int.
> Separately, from a space efficiency perspective, would it be better in the
> case of having a small set of option values to force the type to be an
> unsigned int? That is, if I have a method that takes such an option, which
> of the following method signatures is nowadays preferred?
>
> - (void) someMethodWithOption:(unsigned int)optionValue;
>
> - (void) someMethodWithOption:(NSInteger)optionValue;
>From a space efficiency perspective it's completely irrelevant. Larger
parameters take up at worst very little space, and may take up none at
all depending on your architecture's alignment and minimum size
policies.
If you follow Apple's lead on this, they use typedefs to NSInteger for
enumerators.
Personally I prefer to use the enum itself, or a typedef of it. This
provides additional information about the type to the compiler and the
debugger which allow the former to produce more useful diagnostics and
the latter to produce more useful output.
Mike
_______________________________________________
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