diff mbox

[1/4] targphys.h: Define PRI*PLX format specifier macros

Message ID 1340628316-26267-2-git-send-email-peter.maydell@linaro.org
State New
Headers show

Commit Message

Peter Maydell June 25, 2012, 12:45 p.m. UTC
Define a set of PRI*PLX format specifier macros for working
with target_phys_addr_t types. These follow the standard pattern
for such macros, and are more flexible than TARGET_FMT_plx, which
does not allow specification of field widths.

Suggested-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 targphys.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

Comments

Eric Blake June 25, 2012, 1:31 p.m. UTC | #1
On 06/25/2012 06:45 AM, Peter Maydell wrote:
> Define a set of PRI*PLX format specifier macros for working
> with target_phys_addr_t types. These follow the standard pattern
> for such macros, and are more flexible than TARGET_FMT_plx, which
> does not allow specification of field widths.
> 
> Suggested-by: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  targphys.h |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
> 
> diff --git a/targphys.h b/targphys.h
> index 95648d6..d5b5636 100644
> --- a/targphys.h
> +++ b/targphys.h
> @@ -11,10 +11,26 @@
>  typedef uint32_t target_phys_addr_t;
>  #define TARGET_PHYS_ADDR_MAX UINT32_MAX
>  #define TARGET_FMT_plx "%08x"
> +/* Format strings for printing target_phys_addr_t types.
> + * These are recommended over the less flexible TARGET_FMT_plx,
> + * which is retained for the benefit of existing code.
> + */
> +#define PRIdPLX PRId32

This risks collisions with future POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/inttypes.h.html#tag_13_20

    Macro names beginning with PRI or SCN followed by any lowercase
letter or 'X' may be added to the macros defined in the <inttypes.h> header.

The correct way to do this is to first undefine any potential conflicts,
per this text in
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_01

    If any header in the following table is included, macros with the
prefixes shown may be defined. After the last inclusion of a given
header, an application may use identifiers with the corresponding
prefixes for its own purpose, provided their use is preceded by a #undef
of the corresponding macro.
...
    <inttypes.h> PRI[Xa-z], SCN[Xa-z]
diff mbox

Patch

diff --git a/targphys.h b/targphys.h
index 95648d6..d5b5636 100644
--- a/targphys.h
+++ b/targphys.h
@@ -11,10 +11,26 @@ 
 typedef uint32_t target_phys_addr_t;
 #define TARGET_PHYS_ADDR_MAX UINT32_MAX
 #define TARGET_FMT_plx "%08x"
+/* Format strings for printing target_phys_addr_t types.
+ * These are recommended over the less flexible TARGET_FMT_plx,
+ * which is retained for the benefit of existing code.
+ */
+#define PRIdPLX PRId32
+#define PRIiPLX PRIi32
+#define PRIoPLX PRIo32
+#define PRIuPLX PRIu32
+#define PRIxPLX PRIx32
+#define PRIXPLX PRIX32
 #elif TARGET_PHYS_ADDR_BITS == 64
 typedef uint64_t target_phys_addr_t;
 #define TARGET_PHYS_ADDR_MAX UINT64_MAX
 #define TARGET_FMT_plx "%016" PRIx64
+#define PRIdPLX PRId64
+#define PRIiPLX PRIi64
+#define PRIoPLX PRIo64
+#define PRIuPLX PRIu64
+#define PRIxPLX PRIx64
+#define PRIXPLX PRIX64
 #endif
 #endif