This is the mail archive of the ecos-bugs@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug 1001510] Fix compiler warnings about mismatch between log()format string and argument values.


Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001510

--- Comment #10 from Grant Edwards <grant.b.edwards@gmail.com> 2012-03-09 16:40:04 GMT ---
(In reply to comment #8)

>> Even so, the format specifier for time_t does happen to be a particular
>> problem. So for this file, how about instead using something like:
>> 
>> #define INTFORMAT(_t_) (sizeof(_t_) == sizeof(long long) ? "lld" : "ld")
>>
>> log(LOG_DEBUG, "%s: = %" INTFORMAT(tp->tv_sec) ".%06" INTFORMAT(tp->tv_usec) "\n", __FUNCTION__, 
> 
> That looks like a good solution.

Except it doesn't compile. :)

Concatenation of adjacent string literals only works with string
literals.  It doesn't work with expressions of type (const char *),
even if they can be evaluated at compile time.  The ternary operation
needs to be moved into the pre-processor stage, and that's a problem,
since the pre-processor knows nothing about variable types.

Using "%lld.%06lld" and casting both values to (long long) will work,
but it adds overhead in the most common case today (time_t is 32 bits
and long long is 64).

I'll try to think up something...

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]