Get the Mac OS Processor Architecture at Runtime

Apparently it is of interest to some developers to know whether a Mac OS application is running on an Intel or PPC machine.
The REALbasic target* constants do not tell you this; they tell you the platform(s) for which the executable was compiled.

While you can make reasonable guesses using tricks, the processor architecture information is easily retrieved at runtime using the BSD function NXGetLocalArchInfo.
Its prototype is found in /usr/include/mach-o/arch.h.

extern const NXArchInfo *

NXGetLocalArchInfo returns a NXArchInfo struct.

typedef struct {
const char *name;
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
enum NXByteOrder byteorder;
const char *description;
} NXArchInfo;

Here is some REALbasic sample code that calls NXGetLocalArchInfo and reads the data in the struct.

soft declare function NXGetLocalArchInfo lib "System.framework" () as Ptr

dim NXArchInfo as Ptr = NXGetLocalArchInfo()
if NXArchInfo = nil then
//something went wrong
end if

dim name as String = NXArchInfo.CString(0)
dim cputype as Integer = NXArchInfo.Int32(4)
dim cpusubtype as Integer = NXArchInfo.Int32(8)
dim byteorder as Integer = NXArchInfo.Int32(12)
dim description as String = NXArchInfo.CString(16)

Interpretation of the numeric fields can be found in /usr/include/nano mach/machine.h.