Perl API 类型的 printf 格式说明符

ike*_*ami 3 perl xs

是否有宏提供正确printf的格式说明IVUVSTRLENSize_tSSize_tperlapi 中没有列出。


C 为 提供的类型的格式说明符提供了宏stdint.h,例如uint32_t.

#include <inttypes.h>
#include <stdint.h>

uint32_t i = ...;
printf("i = %" PRIu32 "\n", i);
Run Code Online (Sandbox Code Playgroud)

有没有类似于PRIu32for IV, UV, STRLEN, Size_tand 的东西SSize_t


更大的问题是,我想建议在Windows子系统的Linux Ubuntu上安装排序::键时产生以下编译警告修复:

Key.xs: In function ‘_keysort’:
Key.xs:237:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘IV {aka long int}’ [-Wformat=]
      croak("unsupported sort type %d", type);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
Key.xs: In function ‘_multikeysort’:
Key.xs:547:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘STRLEN {aka long unsigned int}’ [-Wformat=]
   croak("wrong number of results returned "
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Key.xs:547:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘IV {aka long int}’ [-Wformat=]
Run Code Online (Sandbox Code Playgroud)

ike*_*ami 5

  • 对于UV,存在以下宏:

    • UVuf (十进制)
    • UVof (八进制)
    • UVxf (lc 十六进制)
    • UVXf (uc 十六进制)
  • 对于IV,存在以下宏:

    • IVdf (十进制)
  • 对于NV,存在以下宏:

    • NVef(“ %e-ish”)
    • NVff(“ %f-ish”)
    • NVgf(“ %g-ish”)
  • 对于Size_tand STRLEN,使用内置z长度修饰符。[1]

    • %zu (十进制)
    • %zo (八进制)
    • %zx (lc 十六进制)
    • %zX (uc 十六进制)
  • 对于SSize_t,使用内置z长度修饰符。[1]

    • %zd (十进制)

例如,

IV iv      = ...;
STRLEN len = ...;

croak("iv=%" IVdf " len=%zu", iv, len);
Run Code Online (Sandbox Code Playgroud)
  1. 虽然Size_tSSize_t是可配置的,但它们size_tssize_t实践中和实际没有什么不同,并且STRLENSize_t.