EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <20202021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <20202021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: [Bug 1740426] Re: portable printf() spec for size_t, long long, and others
From: Martin Konrad via Core-talk <[email protected]>
To: [email protected]
Date: Tue, 07 Jan 2020 14:53:05 -0000
Mark, you're right, MSVC supports %z for size_t (which is certainly
preferred over the Microsoft-specific %I). This is supported at least
since VS 2015 (https://docs.microsoft.com/en-us/cpp/c-runtime-library
/format-specification-syntax-printf-and-wprintf-functions?view=vs-2015
#size-prefixes-for-printf-and-wprintf-format-type-specifiers). But I'm
not aware of a sane portable way of writing

int64_t i = 42;
printf("Works on Windows only: %I64d\n", i);

other than

printf("Works on all C99-compatible platforms: %"PRId64"\n", i);

Sure the following works

printf("Works on all C99-compatible platforms: %lli\n", (long long)i);

but I always have to pull up the standard to be sure the type I'm
casting to has sufficient size on all platforms. And it also requires
C99.

-- 
You received this bug notification because you are a member of EPICS
Core Developers, which is subscribed to EPICS Base.
Matching subscriptions: epics-core-list-subscription
https://bugs.launchpad.net/bugs/1740426

Title:
  portable printf() spec for size_t, long long, and others

Status in EPICS Base:
  Triaged

Bug description:
  I've been in the habit of using '%lld' and '%zu' to print 'long long'
  and 'size_t' respectively.  However, the windows world needs '%I64d'
  and '%Iu' instead.  It would be nice to have compatibility macros for
  this.

  stdint.h/inttypes.h has a convention for this for the standard fixed
  width types.  eg. PRIx32 for 'uint32_t'.  This is used like:

  > printf("%"PRIx32"\n", (uint32_t)42);

  http://en.cppreference.com/w/c/types/integer

To manage notifications about this bug go to:
https://bugs.launchpad.net/epics-base/+bug/1740426/+subscriptions

Navigate by Date:
Prev: Re: [Bug 1858467] Re: dbExpand.pl outputs records in non-deterministic order Ben Franksen via Core-talk
Next: Re: EPICS 7, pvAccess & static build Johnson, Andrew N. via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <20202021  2022  2023  2024 
Navigate by Thread:
Prev: [Bug 1740426] Re: portable printf() spec for size_t, long long, and others rivers via Core-talk
Next: [Bug 1740426] Re: portable printf() spec for size_t, long long, and others Martin Konrad via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  <20202021  2022  2023  2024 
ANJ, 11 Jan 2020 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·