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

前端 未结 12 968
时光说笑
时光说笑 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 05:55

    On some platforms and for some types there are specific printf conversion specifiers available, but sometimes one has to resort to casting to larger types.

    I've documented this tricky issue here, with example code: http://www.pixelbeat.org/programming/gcc/int_types/ and update it periodically with info on new platforms and types.

提交回复
热议问题