What is the default type for an integer literal (as relates to its use in NSLog)?
What is the default type for an integer literal (as relates to its use in NSLog)?
- Subject: 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 09:35:20 -1000
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,
};
The type matters to the construction of an NSLog statement. If the
type is NSInteger, then it seems the best way (for 32/64 bit
compatibility) to display its value is:
NSLog(@"SomeOptionValue = %ld", (long) SomeOptionValue);
Or so I conclude from reading:
[1] String Format Specifiers
http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
[2] 64-Bit Transition Guide: Type Specifiers
http://developer.apple.com/documentation/Cocoa/Conceptual/Cocoa64BitGuide/ConvertingExistingApp/chapter_4_section_3.html
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;
_______________________________________________
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