I'm having trouble getting the value of a unsigned long long to print to stdout... here's the program:
Code:
// Some code omitted
int main()
{
unsigned long long d, t;
unsigned int f = 0;
d = 5;
t = 9;
printf("d = %lld, t = %lld.\n", d, t);
printf("Is d prime? %d\nIs t prime? %d\n", isPrime(d), isPrime(t));
for(t = 2; f < 1000; t++)
{
if(isPrime(t)) { printf("%lld\n", t); f++; }
}
return 0;
}
It compiles fine, with no errors (GCC, 'gcc -Wall -o primetest.exe primetest.c') but the first few lines of output are:
Code:
d = 5, t = 0.
Is d prime? 1
Is t prime? 0
2
3
5
7
...
It should, by my reasoning, say 'd = 5, t = 9', yet it doesn't.
To complicate things, this only occurs under (you guessed it) Windows. (Windows 98) It compiles fine under Windows, Linux and OS/2, but gives the expected output '...t = 9' only on Linux and OS/2. Windows gives t = 0.
So I tried to simplify it with:
Code:
#include <stdio.h>
int main()
{
unsigned long long a = 1, b = 2, c = 3, d = 4;
printf("Output:");
printf("\na = %lld", a);
printf("\na = %lld, b = %lld", a, b);
printf("\na = %lld, b = %lld, c = %lld", a, b, c);
printf("\na = %lld, b = %lld, c = %lld, d = %lld", a, b, c, d);
printf("\n");
return 0;
}
Which gives:
Code:
Output:
a = 1
a = 1, b = 0
a = 1, b = 0, c = 2
a = 1, b = 0, c = 2, d = 0
Again, only on Windows! OS/2 and Linux once again agree with the output of:
Code:
...
a = 1, b = 2, c = 3, d = 4
I'm clueless as to what's going on... thanks in advance for any help.