Monday, April 16, 2007

Typical Microsoft

Microsoft includes a compiler option "/Za" that disables Microsoft-specific extensions and turns on ANSI C and ANSI C++ compliance. Seems like a good idea if you're writing code that intends to be portable across multiple platforms.

http://msdn2.microsoft.com/en-us/library/0k0w269d(VS.80).aspx

The kicker? Guess what doesn't compile successfully:

#include <windows.h>

Here is the start of the output:

------ Build started: Project: Foo, Configuration: Debug Win32 ------

Compiling...
Foo.cpp
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinNT.h(477) : error C2467: illegal declaration of anonymous 'struct'
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinNT.h(495) : error C2467: illegal declaration of anonymous 'struct'

Yeah, Microsoft's main Platform SDK entry point isn't ANSI C compliant, which basically means there is no way to write a Windows application that doesn't require Microsoft compiler extensions.