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: Sun, 12 Jan 2020 02:41:11 -0000
> Because of the promotion rules these should use the unmodified printf()
> format specifiers %d/i/o/u/x except for the 64-bit types which need the
> %ll modifier, even when building for Windows.
Rather than making assumptions about the mapping to platform-dependent types we should leave these things up to the standard library. Also technically long long is part of C99/C++11.

> #ifndef EPRIuSIZE
> # if defined(vxWorks)
> # define EPRIuSIZE "lu"
> # else
> # define EPRIuSIZE "zu"
> # endif
> #endif
Can we safely assume that pre-C99/C++11 compilers are only used for VxWorks? To be safe, I would suggest to start using %zu with EPICS 7.1. If we do so no EPICS-specific macro is required.

Using %zu as well as the format-string macros for fixed-size integer
types defined by inttypes.h seems consequent and the most portable
solution to me (with EPICS 7.1). Should a new format specifier make it
into the C/C++ standard we can safely replace the ugly macros.

All this is probably affecting support modules more than Base since
fixed-size integer types and printf aren't used that heavily in Base.

-- 
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: Error message binding socket 5076 on vxWorks Mark Rivers via Core-talk
Next: Re: Error message binding socket 5076 on vxWorks Michael Davidsaver 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 Martin Konrad via Core-talk
Next: EPICS 7, pvAccess & static build Torsten Bögershausen 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 ·