start page | rating of books | rating of authors | reviews | copyrights

Book HomeMac OS X for Unix GeeksSearch this book

4.3. Architectural Issues

There are a few architectural issues to be aware of when developing or porting software on Mac OS X. In particular, pointer size, endian-ness, and inline assembly code tend to be the most common issues.

On a 32-bit system, such as Mac OS X running on the G3 or G4, C pointers are 32 bits (4 bytes). On a 64-bit system, they are 64 bits (8 bytes). As long as your code does not rely on any assumptions about pointer size, it should be 64-bit clean. For example, on a 32-bit system, the following program prints "4", and on a 64-bit system, it prints "8":

#include <stdio.h>
int main( )
{
  printf("%d\n", sizeof(void *));
}

Some 64-bit operating systems, such as Solaris 8 on Ultra hardware (sun4u), have a 64-bit kernel space, but support both 32- and 64-bit mode applications, depending on how they are compiled.

CPU architectures are designed to treat the bytes of words in memory as being arranged in big or little endian order. Big endian ordering has the most significant byte in the lowest address, while little endian has the most significant byte at the highest byte address.

The PowerPC is bi-endian, meaning that the CPU is instructed at boot time to order memory as either big or little endian. Additionally, the PowerPC architecture can also switch endian-ness at runtime, although this is generally not done. In practice, bi-endian CPUs run exclusively as big or little endian. In general, Intel architectures are little-endian, while most, but not all, Unix/RISC machines are big-endian. Table 4-3 summarizes the endian-ness of various CPU architectures and operating systems.

Table 4-3. Endian-ness of some operating systems

CPU type

Operating system

Endian-ness

Dec Alpha

Digital Unix

little-endian

Dec Alpha

VMS

little-endian

Hewlett Packard PA-RISC

HP-UX

big-endian

IBM RS/6000

AIX

big-endian

Intel x86

Windows

little-endian

Intel x86

Linux

little-endian

Intel x86

Solaris x86

little-endian

Motorola PowerPC

Mac OS X

big-endian

Motorola PowerPC

Linux

big-endian

SGI R4000 and up

IRIX

big-endian

Sun SPARC

Solaris

big-endian

As far as inline assembly code is concerned--if you've got any--it will have to be lovingly rewritten by hand. Heaven help you if you have to port a whole Just-In-Time (JIT) compiler! For information on the assembler and PowerPC machine language, see the Mac OS X Assembler Guide (/Developer/Documentation/DeveloperTools/Assembler/AssemblerTOC.html).



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.