RafaGago / mini-async-log

Non bloated asynchronous logger
Other
220 stars 20 forks source link

negative numbers #14

Closed funkyshoc closed 7 years ago

funkyshoc commented 7 years ago

Is it true that for logging negative numbers, that you need to cast your variable with a (i64)/etc? Logging negative numbers by having to remember your variable type and therefore cast it correctly for all integer based variables could be very problematic (since many parts of my code use uint64_t and int64_t) Or is it just that the gcc 4.8 I'm running doesn't like some part of the code.

In your example code for example I get the following line of 2=4294966065 instead of 2=-1231:

00000000000.017025326 [err_] message 40, 1=true, 2=4294966065, 3=432.12, 4=param4, 5=0xffffffffffffffff

RafaGago commented 7 years ago

Sounds like a bug

funkyshoc commented 7 years ago

OK FYI so far it is the only showstopper preventing me from using the code in my project. Everything else seems to work quite well.

RafaGago commented 7 years ago

I'll look at it this evening, but it seems easy to fix. It seems to affect only to "int" on x64.

RafaGago commented 7 years ago

In the meantime maybe defining MAL_NO_VARIABLE_INTEGER_WIDTH makes the bug go away.

RafaGago commented 7 years ago

Fixed. It was the printf format specifier that was wrong on linux x64. I replaced it by the macros on inttypes.h

https://github.com/RafaGago/mini-async-log/commit/e9880665952addf069b88e62b5b97ec61392480e

funkyshoc commented 7 years ago

Seems to work thanks much! It was a little bit unintuitive for my c++ app that had to include -D__STDC_FORMAT_MACROS to get it to compile so perhaps worth noting somewhere in the readme/etc.

This is because inttypes.h won't set those PRIi32/etc defines otherwise:

/ The ISO C99 standard specifies that these macros must only be defined if explicitly requested. /

if !defined cplusplus || defined STDC_FORMAT_MACROS

RafaGago commented 7 years ago

It worked as-is for me, but I'll add the macro to the file later so it doesn't need to be manually defined,

RafaGago commented 7 years ago

I added the definition

https://github.com/RafaGago/mini-async-log/commit/d57f420010203dc87b68f8e181bd7246f4b4ad9f

Thanks for the feedback!