Rixstep
 About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Home » Learning Curve » Hotspots

__WIN32__

This can't be an accident. This has to be intentional.


Get It

Try It

__WIN32__: it's a preprocessor variable. Part of a compiler directive. It's set (to nonzero) if the compiler is targeting 'Win32' - in other words the Windows NTx family of Microsoft operating systems. NT 3.1, 3.5, 4.0, 2K, XP, and so forth.

[Actually it doesn't have to be 'set' - but not everybody knows that evidently. Ed.]

There are other variants on __WIN32__ as can be seen in the preamble to the main Core Foundation header file for OS X Leopard 'CFBase.h'.

/*    CFBase.h
    Copyright (c) 1998-2007, Apple Inc. All rights reserved.
*/

There are references __CYGWIN32__ and _WIN32. They're used to define __WIN32__.

#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined (__WIN32__)
#define __WIN32__ 1
#endif

There's also a reference to the Microsoft C compiler.

#if defined(_MSC_VER) && defined(_M_IX86)
#define __i386__ 1
#endif

Once __WIN32__ is defined it's time to include some more header files.

#if defined(__WIN32__)
#include <windows.h>
#include <winsock2.h>
#include <stdint.h>
#include <stdbool.h>

'windows.h' is the big 'catch all' Windows header file; 'winsock2.h' is the (relatively) new and updated sockets header file. This is Windows and nothing but Windows pure plain and simple.

There's more stuff needed to build and use DLLs and so forth.

#if defined(__WIN32__)
    #undef CF_EXPORT
    #if defined(CF_BUILDING_CF)
    #define CF_EXPORT __declspec(dllexport) extern
    #else
    #define CF_EXPORT __declspec(dllimport) extern
    #endif

But this is OS X Leopard; there are similar references in CFBase.h, CFSocket.h, CFString.h, CFNetworkDefs.h, CFSocketStream.h, ExceptionHandlingDefines.h, NSObjCRuntime.h, and a number of Python and Tcl header files - and today any number of Apple software titles run on Windows, right?

Right. But back in the days of Jaguar? Certainly nothing was running on Windows back then, was it?

Here's a snippet from the main header file for Core Graphics anno 2000.

/* CoreGraphics - CGBase.h
 * Copyright (c) 2000 Apple Computer, Inc.
 * All rights reserved.
 */

#ifndef CGBASE_H_
#define CGBASE_H_

#if defined(__WIN32__)
#  if defined(CG_BUILDING_CG)
#    define CG_EXTERN __declspec(dllexport) extern
#  else
#    define CG_EXTERN __declspec(dllimport) extern
#  endif
#  if defined(CG_DEBUG)
#    define CG_PRIVATE_EXTERN CG_EXTERN
#  else
#    define CG_PRIVATE_EXTERN extern
#  endif
#endif

Here's a snippet from CoreFoundation.h.

/*    CoreFoundation.h
    Copyright 1998-2002, Apple, Inc. All rights reserved.
*/

#if defined(__MACH__) || defined(__WIN32__)
#include <CoreFoundation/CFMachPort.h>
#include <CoreFoundation/CFMessagePort.h>
#include <CoreFoundation/CFRunLoop.h>
#include <CoreFoundation/CFSocket.h>
#endif

This goes through Core Foundation sockets (CFSocket.h and NSPort.h); exception handling (NSException.h); file management (NSFileHandle.h and NSFileManager.h); and the Objective-C runtime itself (NSObjCRuntime.h).

It's written so it will compile, build, and run on Windows. Some of it eight years ago.

There are 15 references to __WIN32__ in Tiger's /System, 20 in Leo's /System, 8 in Jaguar's SDK, 15 in Panther's SDK, 29 in Tiger's SDK, and 36 in Leo's SDK.

The number of files referencing __WIN32__ is growing all the time.

I don't like the idea of some evil hacker using my operating system on other than Apple hardware like me.
 - Albert Sims, Saskatchewan

About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Copyright © Rixstep. All rights reserved.