是否有宏提供正确printf的格式说明IV,UV,STRLEN,Size_t和SSize_t?perlapi 中没有列出。
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)
对于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)
Size_t和SSize_t是可配置的,但它们size_t与ssize_t实践中和实际没有什么不同,并且STRLEN是Size_t.