Differences between Windows and macOS

From RAD Studio
Jump to: navigation, search

Go Up to Considerations for Multi-Device Applications


When starting multi-device development for macOS 64-bit (Intel) or macOS 64-bit (ARM), you need to understand and be able to handle many issues, including the issues described here.

Exception Handling Is Different

Mac and Linux systems use Program Counter (PC)-mapped exceptions, whereas Windows (Win32) uses registration records linked on the stack.

You need to adapt your exception handling to the type used on your target platform. In particular, there are differences in the way assembly routines might need to be coded, if it is possible that an exception could be thrown past them. For more information, see PC-Mapped Exceptions#Unwinding Assembly Routines.

On the macOS 64-bit (Intel) and macOS 64-bit (ARM) platform, structured exception handling (__try/__except) is not available. For more information, see MacOS Application Development#Exception Handling.

For general information about exception handling, see:

Alignment Differences between Mac and Windows

  • Alignment issues pertain only to development using Assembler code.
  • A Mac application binary uses 16-byte intervals.
  • The SO (shared object) stack must contain units of 16 bytes.
  • The Mac environment kills any process that does not match the 16-byte alignment.
  • See Eli's blog about the stack on Mac: http://blogs.embarcadero.com/eboling/2009/10/13/5620
  • WideChar vs. wchar_t (wchar_t is 2 bytes on Windows vs. 4 bytes on macOS)
  • tchar.h does not work on a Mac (or Linux)

Two Delphi compiler directives control alignment:

Accessing Global Variables in ASM on Windows and macOS

On macOS 64-bit (Intel) and macOS 64-bit (ARM), global variables are addressed using position independent code (PIC), and this affects your ability to access globals in ASM.

If you have declared a global variable like this:

var
  GlobalVar: UInt32 = $12345678;

Then you expect to get the VALUE of this variable in ASM code like this:

function GetGlobalVar: UInt32;
asm
  mov eax,[GlobalVar]
end;

However, this code works correctly (as expected) on Windows, macOS 64-bit (Intel), and macOS 64-bit (ARM) only if the global variable is declared in the SAME unit as the ASM routine. If GlobalVar resides in a different unit, then GetGlobalVar behaves differently on Windows and macOS:

  • On Windows, GetGlobalVar returns the VALUE of GlobalVar (as expected).
  • On OSX, GetGlobalVar returns the ADDRESS of GlobalVar (this can have problematic consequences).

To access a global variable, we recommend that you do the following:

function GetGlobalVar: UInt32;
begin
  asm
    MOV EAX, [EBX].OFFSET GlobalVar
    MOV EAX, [EAX]
  end;
end;

The initial 'begin' clause is needed to set up the required PIC prologue code that sets up EBX for this operation.

Windows Libraries Are Only Available to Windows Applications

Keep in mind these differences:

  • A macOS 64-bit (Intel) and macOS 64-bit (ARM) application can call either FireMonkey APIs or POSIX APIs.
  • A macOS 64-bit (Intel) and macOS 64-bit (ARM) application cannot call Windows APIs (neither 32-bit nor 64-bit).
  • A Windows application can be enabled to call either 32-bit Windows or 64-bit Windows APIs.

Equivalent File Extensions on the Mac and on Windows

Mac File Extension Windows File Extension
.o (object file)
.obj (object file)
.dylib (dynamic library)
.dll (dynamically linked library)

Equivalent Command-Line Elements on the Mac and on Windows

Element On the Mac On Windows

Command-line interface

Apple Terminal window (UNIX-based)

cmd Window (Start | cmd)

Command prompt

>

To reference the current directory, start your command with ./.

>

Directory list command

ls
dir 

Change directory command

  • cd ..
    (move up one level)
  • cd directory
    (move to the specified directory)
  • cd ..
    (move up one level)
  • cd directory
    (move to the specified directory)

File-name separator

/
\

See Also