How can one print a size_t variable portably using the printf family?

前端 未结 12 1127
时光说笑
时光说笑 2020-11-22 05:40

I have a variable of type size_t, and I want to print it using printf(). What format specifier do I use to print it portably?

In 32-bit ma

12条回答
  •  梦谈多话
    2020-11-22 06:06

    Will it warn you if you pass a 32-bit unsigned integer to a %lu format? It should be fine since the conversion is well-defined and doesn't lose any information.

    I've heard that some platforms define macros in that you can insert into the format string literal but I don't see that header on my Windows C++ compiler, which implies it may not be cross-platform.

提交回复
热议问题