Correct way to use scanf / printf (and family) with fixed size types?

前端 未结 2 1558
忘掉有多难
忘掉有多难 2020-12-16 13:47

Reading this SO question, I started wondering - what is the correct way to use scanf/printf (and family) with fixed size types?

For example

2条回答
  •  误落风尘
    2020-12-16 14:10

    The correct way is to use inttypes.h which defines standard macros for printf family and the scanf family, e.g.

    printf ("%" PRId16, short_int);
    scanf ("%" SCNd16, &short_int);
    

提交回复
热议问题