tags:

views:

67

answers:

2

Hi All,

What is the best practice for moving to 64-bit on OS X? Using the 10.6 SDK and 64-bit intel as my SDK and target.

I have int32 types to change

Does OS X have an 'int64' or would one use a 'long long'?

Where might I find a resource to available data types?

What other issues are there?

+6  A: 

Apple has exactly the documentation you want, called 64-bit transition guide. OS X uses LP64 model, so you should use

#ifdef __LP64__

etc. to conditionally compile things according to the bit width, especially if you want your code to be 32bit/64bit clean. For Cocoa, see 64 bit Transition Guide for Cocoa. There, NSInteger has an appropriate bit width according to the mode, so you don't have to deal with the bit width yourself.

Yuji
@yuji - we need the app to be 64-bit only.
ML
+1  A: 

Both long and long long are 64-bit types when building 64-bit on OS X. In addition, you can use the int64_t and uint64_t types defined in <stdint.h> if you need to specify that an integer is exactly 64 bits wide.

You generally don't need to change existing int32 types in your program, unless they're being used to perform pointer arithmetic (or otherwise depend on them being the same size as a pointer). 32 bit arithmetic continues to work just fine in 64-bit programs. If you do have variables that must be the same size as a pointer, use the uintptr_t type, which will work in both 32- and 64-bit builds.

The other situation where you might need to make changes is if a API expects to be passed (or returns) a size_t or long or intptr_t, and you've been using int all this time, instead of what the function in question actually specifies. It will have worked on 32-bit builds, but may introduce errors when built for 64-bit.

Yuji's suggestion of reading the 64-bit transition guides is excellent advice.

Stephen Canon
@stephen - We need the app to be 64-bit only.
ML
@stephen - Can you explain a bit more? I want to be 64-bit only. I am using the 10.5 SDK and 64-bit intel as my target settings. I have int16, in32 and some longs.
ML
@ML - have you tried just building your application for 64-bit without changing anything? If your code doesn't do anything "clever" with pointers, it may work just fine as is.
Stephen Canon