[ovs-dev] [PATCH v2] packet: proper return type for vlan_tci_to_pcp()

Shu Shen shu.shen at gmail.com
Thu Feb 2 23:15:26 UTC 2017


On macOS, PRIu8 and PRIx8 the specifiers are not promoted to 'u' and 'x'
respectively.

For example, for PRIu*, on Mac OS, /usr/include/inttypes.h:

 #  define __PRI_8_LENGTH_MODIFIER__ "hh"
 #  define __PRI_64_LENGTH_MODIFIER__ "ll"
 #  define PRIu8         __PRI_8_LENGTH_MODIFIER__ "u"
 #  define PRIu16        "hu"
 #  define PRIu32        "lu"
 #  define PRIu64        __PRI_64_LENGTH_MODIFIER__ "u"

While on Linux/glibc, /usr/include/inttypes.h:

 # define PRIu8          "u"
 # define PRIu16         "u"
 # define PRIu32         "u"
 # define PRIu64         __PRI64_PREFIX "u"

where all PRIu* except PRIu64 are the same.

Therefore, using PRIu8 or PRIx8 with the int return type of
vlan_tci_to_pcp() is causing compiler warnings on macOS.

The first patch in this patchset fixes the return types of vlan_tci_to_pcp()
and vlan_tci_to_cfi() functions from int to uint8_t, as 8-bit unsigned int is
the expected data type for these two functions. After this patch, warning
message Wformat would no longer occur for these two functions on macOS.

The second patch could be considered as cosmetic or more about coding style,
but it uses PRI* specifier consistently when formating the return values of
vlan_tci_to_pcp(). Although desirable in my opinion, this second patch may be
applied independently from the first one.



More information about the dev mailing list