Re: Variable type representations

2016-03-11 Thread Quincey Morris
On Mar 11, 2016, at 12:55 , Quincey Morris 
 wrote:
> 
> just use ‘unsignedIntegerValue’

Oops, forgot you were starting from a NSString, so there’s no unsigned variant. 
Use ‘integerValue’ and cast the result (possibly doing a run-time check for a 
negative value first).

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Variable type representations

2016-03-11 Thread Quincey Morris
On Mar 11, 2016, at 12:43 , Carl Hoefs  wrote:
> 
> Q1: How can 'long' and 'long long' have the same 8-byte representation? 

Go complain to the gods of C. That language is responsible for the concept:

sizeof (int) <= sizeof (long) <= sizeof (long long)

Note the “=“ signs. (It’s all about getting the “natural-est” variable size on 
heterogeneous platforms.)

> Q2: How to get an unsigned long int value from an NSString? Use NSInteger?

For any reasonable (i.e. 64-bit) OS X app, just use ‘unsignedIntegerValue’ and 
cast the result. If you want compatibility with 32-bit architecture, use 
‘unsignedLongLongValue’ and cast the result. (You can use the latter in either 
case, but it’s a bit of a mouthful.)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com