Might be interestingly related: on 64-bit Windows, long is also still
32-bit ( https://msdn.microsoft.com/fi-fi/library/s3f49ktz.aspx ), so
printing a %ld will be printing a 32-bit quantity there as well. On
64-bit Linux targets long is 64-bit like Brion mentioned. %lld is the
formatting specifier for long longs.

In EM_ASM signatures, all parameters that go in are cast to doubles,
and possible returns are either int with EM_ASM_INT or double with
EM_ASM_DOUBLE.

2018-02-20 13:49 GMT+02:00 Brion Vibber <[email protected]>:
> The emscripten environment is 32-bit, while it looks like your Linux is
> 64-bit. If you need integers larger than will fit in 32 bits, you'll need to
> use a long long instead of a long.
>
> I'm not sure offhand if there's a way to get a long long result from EM_ASM
> but double will work there.
>
> -- brion
>
> On Tue, Feb 20, 2018 at 1:16 AM Александр Гурьянов <[email protected]>
> wrote:
>>
>> Hi, I found that simplest function getCurrentTimeMs() work different
>> in browser environment (tested on origin/incoming). Code is simple:
>>
>> #include <sys/time.h>
>> #include <cstdio>
>>
>> int main(int, char**) {
>>     static struct timeval tp;
>>     gettimeofday(&tp, 0);
>>     printf("%ld %ld %ld\n", tp.tv_sec, tp.tv_usec, tp.tv_sec * 1000 +
>> tp.tv_usec / 1000);
>>     return 0;
>> }
>>
>> In native (linux) environment:
>> 1519117387 651928 1519117387651
>>
>> In browser/node.js (em++ time.cpp -o time.js):
>> 1519117389 245000 -1301033539
>>
>> Looks like overflow problem:
>>
>> #include <sys/time.h>
>> #include <cstdio>
>>
>> int main(int, char**) {
>>     printf("%ld\n", 1519117387 * 1000l);
>>     return 0;
>> }
>>
>> native:
>> 1519117387000
>>
>> node.js:
>> -1301035784
>>
>> only using 1000ll helps.
>>
>> For code:
>>
>> long time = 1519117387 * 1000l;
>>
>> emscripten compilator reports:
>> time.cpp:5:28: warning: overflow in expression; result is -1301035784
>> with type 'long' [-Winteger-overflow]
>>
>> native is ok. Anyway it's little bit strange, don't remember this
>> problem before. For emscripten I should store ms in long long type?
>> Don't understand.
>>
>> This code also return negative values:
>>
>> #include <sys/time.h>
>> #include <cstdio>
>> #include <emscripten.h>
>>
>> int main(int, char**) {
>>     long long time = EM_ASM_INT((
>>         return Date.now();
>>     ));
>>     printf("%lld\n", time);
>>     return 0;
>> }
>>
>> So only way is use EM_ASM_DOUBLE? is it safe?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to