summaryrefslogtreecommitdiff
path: root/CodingStyle
diff options
context:
space:
mode:
authorAlin Serdean <aserdean@cloudbasesolutions.com>2013-11-25 23:38:48 -0800
committerBen Pfaff <blp@nicira.com>2013-11-25 23:38:59 -0800
commit34582733d9aad82bba60f4bf986b62d58412502a (patch)
tree9f42e24f813d7059b6c0ef529e1b631b443e53cb /CodingStyle
parent4d3daf048134e8c375fdadcec7e51d1dc28fe0b6 (diff)
downloadopenvswitch-34582733d9aad82bba60f4bf986b62d58412502a.tar.gz
Avoid printf type modifiers not supported by MSVC C runtime library.
The MSVC C library printf() implementation does not support the 'z', 't', 'j', or 'hh' format specifiers. This commit changes the Open vSwitch code to avoid those format specifiers, switching to standard macros from <inttypes.h> where available and inventing new macros resembling them where necessary. It also updates CodingStyle to specify the macros' use and adds a Makefile rule to report violations. Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com> Co-authored-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'CodingStyle')
-rw-r--r--CodingStyle16
1 files changed, 15 insertions, 1 deletions
diff --git a/CodingStyle b/CodingStyle
index 2f24ee396..c6e1a6186 100644
--- a/CodingStyle
+++ b/CodingStyle
@@ -394,7 +394,21 @@ from <stdint.h>.
integer types. Use the PRId<N>, PRIu<N>, and PRIx<N> macros from
<inttypes.h> for formatting them with printf() and related functions.
- Use %zu to format size_t with printf().
+ For compatibility with antique printf() implementations:
+
+ - Instead of "%zu", use "%"PRIuSIZE.
+
+ - Instead of "%td", use "%"PRIdPTR.
+
+ - Instead of "%ju", use "%"PRIuMAX.
+
+Other variants exist for different radixes. For example, use
+"%"PRIxSIZE instead of "%zx" or "%x" instead of "%hhx".
+
+ Also, instead of "%hhd", use "%d". Be cautious substituting "%u",
+"%x", and "%o" for the corresponding versions with "hh": cast the
+argument to unsigned char if necessary, because printf("%hhu", -1)
+prints 255 but printf("%u", -1) prints 4294967295.
Use bit-fields sparingly. Do not use bit-fields for layout of
network protocol fields or in other circumstances where the exact