C (gcc), x64 only, 37 bytes
Try it online!
1 for Windows,
0 for non-Windows.
You wanted a "creative solution"? Here you go. Unfortunately, it isn't as short or portable as the other C solution. (TODO: x86, ARM, and ARM64 polyglot /s)
// We need both m and _m because macOS uses leading underscores for
// C symbols, while Windows and Linux do not.
// We manually encode these in the golfed code to save space.
// eax = edx
xchg eax, edx // 0x92
ret // 0xC3
int m(int, int, int);
// The first parameter can be anything, I use 2 for ease of explanation.
return m(2, 1, 0);
What does it do? It uses the fact that Windows and Linux (and Mac, BSD, etc) use different calling conventions on x64.
So, when GCC tries to call
m(2, 1, 0), on Windows it will use the Microsoft x64 calling convention (
mov ecx, 2
mov edx, 1
mov r8d, 0
However, on Linux, Mac, BSD, etc, it will use the System V calling convention (
mov edi, 2
mov esi, 1
mov edx, 0
As I have bolded,
edx is used on both platforms, but since they represent different parameters in the calling conventions, Windows and non-Windows will get different values.
With some inline assembly, we can get GCC to return the value of
edx instead of the third parameter.
To test how it would function on Windows, simply uncomment the prototype at the top, which uses an attribute to force GCC to use the Microsoft ABI.