[ovs-dev] [PATCH] Use PRIu32 format for ofp_port_t

Shu Shen shu.shen at gmail.com
Sat Jan 14 18:01:47 UTC 2017


Sorry I missed the list in my reply.

On Sat, Jan 14, 2017 at 9:56 AM, Shu Shen <shu.shen at gmail.com> wrote:
> Mac OS differs from glibc in its definition of the PRI* format strings.
>
> 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 PRIx32        "x"
>  #  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.
>
> On Sat, Jan 14, 2017 at 8:42 AM, Ben Pfaff <blp at ovn.org> wrote:
>> On Fri, Jan 13, 2017 at 05:51:00PM -0800, Shu Shen wrote:
>>> Although ofp_port_t uses a 16-bit range, it is defined as a 32-bit type.
>>> The format strings throughout the code base were using PRIu16 for
>>> ofp_port_t which leads to the compiler to throw Wformat message on
>>> platforms that don't promote 16-bit to 32-bit integers, e.g., on macOS.
>>>
>>> Signed-off-by: Shu Shen <shu.shen at gmail.com>
>>
>> It makes sense to use PRIu32 for a 32-bit type, so I applied this to
>> master and branch-2.6.  Thank you.
>>
>> But I don't understand the statement that Mac OS does not promote 16-bit
>> integer to 32-bit integers.  According to
>> https://developer.apple.com/library/content/documentation/Darwin/Conceptual/64bitPorting/transition/transition.html,
>> on Mac OS "short" is a 16-bit integer and "int" is a 32-bit integer.
>> Under C rules, unsigned types shorter than unsigned int are promoted to
>> unsigned int when they are passed as arguments, which means that on Mac
>> OS, 16-bit types are converted to 32-bit ones when they are passed as
>> arguments.  Am I missing something subtle?


More information about the dev mailing list