I pasted and posted too quick. I think you wanted something like this:
# include<stdio.h>
# include<stddef.h>
int main(void) {
ptrdiff_t last, next;
for (last = 32767; (next = 2 * (double)last + 1)> last; ) {
printf ("last = %lld double = %f next = %lld\n",
(long long)last, 2 * (double)last, (long long)next);
last = next;
}
printf("%lld\n", (long long) last);
return 0;
}
With the MinGW64 4.5 I just installed I got the same exact result of
yours on the first run (without any optimization), except that setting
the -O2 flag I got this:
last = 32767 double = 65534.000000 next = 65535
last = 65535 double = 131070.000000 next = 131071
last = 131071 double = 262142.000000 next = 262143
last = 262143 double = 524286.000000 next = 524287
last = 524287 double = 1048574.000000 next = 1048575
last = 1048575 double = 2097150.000000 next = 2097151
last = 2097151 double = 4194302.000000 next = 4194303
last = 4194303 double = 8388606.000000 next = 8388607
last = 8388607 double = 16777214.000000 next = 16777215
last = 16777215 double = 33554430.000000 next = 33554431
last = 33554431 double = 67108862.000000 next = 67108863
last = 67108863 double = 134217726.000000 next = 134217727
last = 134217727 double = 268435454.000000 next = 268435455
last = 268435455 double = 536870910.000000 next = 536870911
last = 536870911 double = 1073741822.000000 next = 1073741823
last = 1073741823 double = 2147483646.000000 next = 2147483647
last = 2147483647 double = 4294967294.000000 next = 4294967295
last = 4294967295 double = 8589934590.000000 next = 8589934591
last = 8589934591 double = 17179869182.000000 next = 17179869183
last = 17179869183 double = 34359738366.000000 next = 34359738367
last = 34359738367 double = 68719476734.000000 next = 68719476735
last = 68719476735 double = 137438953470.000000 next = 137438953471
last = 137438953471 double = 274877906942.000000 next = 274877906943
last = 274877906943 double = 549755813886.000000 next = 549755813887
last = 549755813887 double = 1099511627774.000000 next = 1099511627775
last = 1099511627775 double = 2199023255550.000000 next = 2199023255551
last = 2199023255551 double = 4398046511102.000000 next = 4398046511103
last = 4398046511103 double = 8796093022206.000000 next = 8796093022207
last = 8796093022207 double = 17592186044414.000000 next = 17592186044415
last = 17592186044415 double = 35184372088830.000000 next = 35184372088831
last = 35184372088831 double = 70368744177662.000000 next = 70368744177663
last = 70368744177663 double = 140737488355326.000000 next = 140737488355327
last = 140737488355327 double = 281474976710654.000000 next =
281474976710655
last = 281474976710655 double = 562949953421310.000000 next =
562949953421311
last = 562949953421311 double = 1125899906842622.000000 next =
1125899906842623
last = 1125899906842623 double = 2251799813685246.000000 next =
2251799813685247
last = 2251799813685247 double = 4503599627370494.000000 next =
4503599627370495
last = 4503599627370495 double = 9007199254740990.000000 next =
9007199254740991
last = 9007199254740991 double = 18014398509481982.000000 next =
18014398509481984
last = 18014398509481984 double = 36028797018963968.000000 next =
36028797018963968
last = 36028797018963968 double = 72057594037927936.000000 next =
72057594037927936
last = 72057594037927936 double = 144115188075855870.000000 next =
144115188075855872
last = 144115188075855872 double = 288230376151711740.000000 next =
288230376151711744
last = 288230376151711744 double = 576460752303423490.000000 next =
576460752303423488
last = 576460752303423488 double = 1152921504606847000.000000 next =
1152921504606846976
last = 1152921504606846976 double = 2305843009213694000.000000 next =
2305843009213693952
last = 2305843009213693952 double = 4611686018427387900.000000 next =
4611686018427387904
last = 4611686018427387904 double = 9223372036854775800.000000 next =
-9223372036854775808
-9223372036854775808
Just out of curiosity, are these warnings expected?
In function 'main':|
main.c|10|warning: unknown conversion type character 'l' in format|
main.c|10|warning: format '%f' expects type 'double', but argument 2 has
type 'ptrdiff_t'|
main.c|10|warning: unknown conversion type character 'l' in format|
main.c|10|warning: too many arguments for format|
main.c|14|warning: unknown conversion type character 'l' in format|
main.c|14|warning: too many arguments for format|
||=== Build finished: 0 errors, 6 warnings ===|
Maybe I downloaded a buggy package? Heck, better that I stop posting
this stuff and I get something sure about my toolchain.