Re: Porting some software to OpenBSD
On Sun, Jan 06, 2019 at 03:22:50AM +, Adam Steen 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 If you want to print an int type from , use the printf() format defined for that type in : uint64_t freq; /* ... */ printf("freq is %" PRIu64 " Hz\n", freq); See e.g. https://en.cppreference.com/w/c/types/integer Cheers, -- Andreas Kusalananda Kähäri, National Bioinformatics Infrastructure Sweden (NBIS), Uppsala University, Sweden.
Re: Porting some software to OpenBSD
On Sat, Jan 5, 2019 at 7:25 PM Adam Steen wrote: > 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? > Option 1) log(DEBUG, "Solo5: clock_init(): freq=%llu\n", (unsigned long long)freq); Option 2) #include log(DEBUG, "Solo5: clock_init(): freq=%"PRIu64"\n", freq); Software native to OpenBSD uses option 1 when necessary. Philip Guenther
Re: Porting some software to OpenBSD
Adam Steen wrote: > '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? The easy fix is log("%llu", (long long)freq) which should work everywhere.
Re: Porting some software to OpenBSD
Nathan Hartman wrote: > On Sat, Jan 5, 2019 at 10:27 PM Adam Steen 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. You mean errors. Some of these errors are involved in what makes it so hard for them to handle 64-bit time_t, and wait until you see the incredible scheme they have planned for finally making 64-bit off_t the default...
Re: Porting some software to OpenBSD
On Sat, Jan 5, 2019 at 10:27 PM Adam Steen 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.
Porting some software to OpenBSD
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