On Jul 29, 2008, at 8:44 PM, Steve Christensen wrote:

On Jul 29, 2008, at 12:56 PM, Jack Skellington wrote:

Is there a way to determine if an App is running on Intel or PPC
from within the App?

Depending on what you're trying to do, you can go at least a couple routes at build time.

If you only care about endianness:

#ifdef __BIG_ENDIAN__
#ifdef __LITTLE_ENDIAN__


If you care about the actual architecture:

#ifdef __ppc__          // 32-bit PPC
#ifdef __ppc64__        // 64-bit PPC
#ifdef __i386__         // 32-bit Intel
#ifdef __x86_64__       // 64-bit Intel


There are also parallel ones defined in /usr/include/ TargetConditionals.h:

#if TARGET_RT_LITTLE_ENDIAN
#if TARGET_RT_BIG_ENDIAN

#if TARGET_CPU_PPC
#if TARGET_CPU_PPC64
#if TARGET_CPU_X86
#if TARGET_CPU_X86_64

Note that all of these detect the compile-time targeted architecture. In rare case (e.g. Rosetta), this may be different than the actual architecture of the machine at runtime. Generally, you probably don't care. (A PPC binary running on an Intel Mac should probably not do anything differently than it would on a real PPC Mac.)

If you do care, see this: 
http://developer.apple.com/documentation/MacOSX/Conceptual/universal_binary/universal_binary_exec_a/chapter_950_section_7.html

That describes a technique using the sysctl API. That API can also be used to determine lots of other aspects of the runtime environment, too.

Cheers,
Ken
_______________________________________________

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

This email sent to [EMAIL PROTECTED]

Reply via email to