Cross platform... You wish
C
I will take a stab at it with a textbook-like example:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a[] = {1,2,3,4,5,6,7,8};
if (sizeof(&a) > sizeof(int)) {
printf("foo %d %d\n", *(int *)a, *(long *)a);
} else {
printf("bar %d %d\n", *(int *)a, *(long *)a);
}
}
64-bit Platform prints: foo
32-bit Platform prints: bar
Little Endian Platforms: 67305985
Big Endian Platforms: 16909060
So there is at least 4 combinations.
On top of that, some very old platforms has int
defined as 16-bits. And some platform has long
defined as 64-bits. So the result will be different as well.
C has been quite platform specific, if you dig deep enough. It is not hard to come up with thousands of combinations (2^10+).
16/32/64-bit x86/x64 assembly, 16 bytes, 4 combinations
Byte-code:
31 C9 41 E2 0A 66 49 41 74 05 0F 00 C0 03 C1 C3
Disassembly (16-bit):
xor cx, cx ;cx=0
inc cx ;cx=1
loop l1 ;fall through
dec cx ;cx=FFFF
inc ecx ;cx=0000
je l1 ;branch taken
;...
l1: ret
Disassembly (32-bit):
xor ecx, ecx ;ecx=0
inc ecx ;ecx=1
loop l1 ;fall through
dec cx ;ecx=0000FFFF
inc ecx ;ecx=00010000
je l1 ;branch not taken
sldt ax ;detect VMware, VirtualPC, Parallels, etc.
add ecx, eax ;conditionally modify ecx
l1: ret
Disassembly (64-bit):
xor ecx, ecx ;rcx=0 (implicit 64-bit zero-extension)
loopq l1 ;rcx becomes FFFFFFFFFFFFFFFF, branch taken
...
l1: ret
It returns:
- CX=0000 in 16-bit mode;
- ECX=10000 in 32-bit non-virtual mode;
- ECX=(random) in 32-bit virtual mode;
- RCX=FFFFFFFFFFFFFFFF in 64-bit mode.