Closed Bug 514071 Opened 15 years ago Closed 15 years ago

warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 4 has type ‘long unsigned int’

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
minor

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta1-fixed

People

(Reporter: mrbkap, Assigned: graydon)

References

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

Normally these are pretty easy to fix, but I'm really not sure about this one the full g++ output is:

jscntxt.cpp: In function ‘void DumpEvalCacheMeter(JSContext*)’:
jscntxt.cpp:559: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 4 has type ‘long unsigned int’

I think the problem is that I'm on a 64-bit machine. The actual type in question is uint64 so on a 64 bit Linux system only wants %lu and really wants %llu on a 32 bit system. This is one of those cases where I really miss C++ iostreams.
Iostreams, bah -- isn't there a new and portable %-escaped format specifier for ptrdiff_t and other standard int types?

/be
You can use the horrid macros defined in inttypes, although we don't have that on Windows, I'm sure:
http://www.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html
What Ted said!  Shouldn't be hard, just more of the same of jsstdint.h.
Yeah. You want the string-pasted incantation "%" PRIu64. Or PRIuPTR if you're doing pointer-sized, as Brendan suggested. Either way, I'll take this, it's just janitorial.

We may wind up having to duplicate platform-neutral definitions a little in nanojit's VMPI layer.
Assignee: general → graydon
This has gotten a lot worse now that jstracer.cpp is built on x64. I now get 28 of these in that file alone.
Casting the args to 'long long unsigned' is also a possibility, one that's arguably no uglier than PRIuWhatever.
(In reply to comment #6)
> Casting the args to 'long long unsigned' is also a possibility, one that's
> arguably no uglier than PRIuWhatever.

That's been the traditional solution in js/src.

Someone do something, my warning greps are non-zero which makes me itchy.

/be
(In reply to comment #8)
> stops gcc complaining on 32/64-bit opensuse 11

Might be a bit overkill, but .. in every place where the 
difference between two pointers is printed, I widened it
to long long int and used %lld.  This seems simpler than
figuring out a type and format specifier which reliably
means "machine word sized signed int" on all platforms,
particularly Win64.
Luke, what do you think? Do we have to do this? Any better ideas?
Attachment #401133 - Flags: review+
The better option is to use PRIuWhatever in our format strings, IMO. But to get those definitions right involves autoconfery as well as some fallback stuff in jsinttypes or jsstdint. I keep starting on that and then getting distracted by other work. It requires a lot of tedious fiddling across platforms.
(In reply to comment #11)
> Luke, what do you think? Do we have to do this? Any better ideas?

I say we let template argument deduction do the work instead.  IOStreams isn't the only way to get this; assuming we don't mind converting a single "A%dC%p" formatted ::fprintf call into 4 separate ::fprintf calls (this is for debug output, right?), it would be pretty easy to throw in a few hollow templates to bring us type-inferred goodness:

namespace js {
 template <class T1> void fprint(FILE *f, const T1 &t1) {
  ::fprintf(f, tl::TypeToFormatString<T1>::result, t1);
 }
 template <class T1,class T2> void fprint(FILE *f, const T1 &t1, const T2 &t2) {
  ::fprintf(f, tl::TypeToFormatString<T1>::result, t1);
  ::fprintf(f, tl::TypeToFormatString<T2>::result, t2);
 }
 ...
}

uint64_t l;
js::fprint(f, "got: ", l);

Getting formatting etc in on the game would involve further trickery,
but it seems eminently doable.
Pushed to TM as 09e12b174aca.
Keywords: checkin-needed
Whiteboard: fixed-in-tracemonkey
That should be (length + 1) * sizeof(jschar), right? rs=me on followup.

/be
Comment 15 was meant for bug 516458 but I dropped it here based on a commit message typo ;-).

/be
http://hg.mozilla.org/mozilla-central/rev/9131d01c2d2a
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Flags: in-testsuite-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: