lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 7/29/2011 7:47 PM, Lorenzo Donati wrote:
On 27/07/2011 23.10, Luiz Henrique de Figueiredo wrote:
> =big
2500000000
> =string.format('%d', big)
-2147483648
[snip]
---------------------------------------------------------------------
#include <stdio.h>
#include <limits.h>

int main()
{

printf("long long width: %d bit\n", sizeof(long long) * CHAR_BIT );
long long nnn = 2LL << 30; /* 2^31 */
double ddd = nnn;
nnn = ddd; /* check round-trip */
printf( "ddd = %.0f\n", ddd );
printf( "nnn = %lld\n", nnn );

}
---------------------------------------------------------------------

And compiled it this way:
gcc test.c -c -O2 -Wall -pedantic -std=c90
gcc test.o -o test.exe -O2 -Wall -pedantic -std=c90
[snip]
So there must be some strange combination of compiler flags in the
standard makefile that makes GCC do the wrong thing for %lld in
printf.

A wild guess, perhaps -std=c90 pulls in the mingwex versions of *printf. Without the -std=c90, it doesn't work. But putting -std=c90 and building the Lua DLL does not appear to work... documentation on mingwex is thin on the Internet.

What does work is using __mingw_sprintf in str_format().

Alternatively, Win32 has the "I64" specifier. I dunno how portable it is across versions of Win32 >=Win2K.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia