On Sat, Jan 5, 2019 at 10:27 PM Adam Steen <[email protected]> wrote:
> Hi All > > I have a question about string (printf) formatting. > > I have a variable > > 'uint64_t freq' > > which is printed with > > 'log(DEBUG, "Solo5: clock_init(): freq=%lu\n", freq);' > > but am getting the following error > > ' > error: format specifies type 'unsigned long' but the argument has type > 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat] > freq); > ^~~~~~~~ > 1 error generated. > ' > > The easy fix is to change the format to '%llu', but this brakes FreeBSD > and Linux. Am i missing something or should i be investigating the log > implementation? > > > Cheers > Adam There are often subtle differences like this between platforms. One possibility is to define preprocessor macros that expand to the correct printf format modifier for the platform. I've seen several implementations over the years. One that comes to mind (only because I saw it recently) is pstdint.h: http://www.azillionmonkeys.com/qed/pstdint.h (I don't know if that works correctly on OpenBSD. Also it defines a bunch of other things; that may be helpful, or unhelpful!) A more fully featured library that deals with platform differences is APR, the Apache Portable Runtime. I think there are also such definitions there.

