Closed Bug 1186126 Opened 4 years ago Closed 4 years ago

note that integerPrintfMacros.h is incompatible with NSPR printf-like functions


(Core :: MFBT, defect)

Not set



Tracking Status
firefox42 --- fixed


(Reporter: oliver.henshaw, Assigned: oliver.henshaw)



(1 file, 1 obsolete file)

I wanted to log a PRTime using mozilla/Logging.h and thought that integerPrintfMacros.h would allow me to specify a portable format string, i.e. PRId64.

But it didn't work and indeed "%ld" gave the same nonsense value. Only "%lld" worked as expected. After a while I realised this was by design, the logging functions use prlog.h and nspr defines its own set of printf-like functions with a different definition of format strings to that in C99, as noted in nsprpub/pr/include/prprf.h
Attachment #8636717 - Flags: review?(nfroyd)
Comment on attachment 8636717 [details] [diff] [review]
Add note warning about incompatibility with NSPR printf-like functions

Review of attachment 8636717 [details] [diff] [review]:

r=me with the change below.

::: mfbt/IntegerPrintfMacros.h
@@ +9,5 @@
>  #ifndef mozilla_IntegerPrintfMacros_h_
>  #define mozilla_IntegerPrintfMacros_h_
>  /*
> + * Intended for use with libc's printf function family. Should not be used with

I think it's a bit redundant to include the bit about libc.  How about:

"NB: These macros should not be used with the NSPR printf-like functions or their users, e.g. mozilla/Logging.h.  If you need to use NSPR's facilities, see the comment on supported formats at the top of nsprpub/pr/include/prprf.h."
Attachment #8636717 - Flags: review?(nfroyd) → review+
Attachment #8636717 - Attachment is obsolete: true
No try run needed as it's a comment only change and I definitely haven't fat-fingered the keyboard.
Keywords: checkin-needed
Assignee: nobody → oliver.henshaw
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
You need to log in before you can comment on or make changes to this bug.