请问Posix的供应格式字符串宏的printf / scanf的? [英] Does Posix supply format string macros for printf/scanf?

查看:104
本文介绍了请问Posix的供应格式字符串宏的printf / scanf的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的printf scanf函数在C函数家庭消耗对应于基本的原始格式说明了一把数据类型&ndash的; %d个 INT %LLU 无符号长long int类型

The printf and scanf families of functions in C consume a handful of primitive format specifiers that correspond to the fundamental data types – %d for int, %llu for unsigned long long int, etc.

不过,也有大量的标准化的类型别名,一个想在实践中使用,如的int32fast_t ,和一个不能也不应该不必知道底层的基本类型。对于 stdint.h 的别名,C标准谢天谢地指定了一组宏来生成相应的格式字符串,如 PRI32 inttypes.h

However, there are a large number of standardized type aliases that one would like to use in practice, such as int32fast_t, and one cannot and should not have to know the underlying fundamental type. For the aliases in stdint.h, the C standard thankfully specifies a set of macros to generate the corresponding format strings, like PRI32, in inttypes.h.

有没有类似的组宏对POSIX的? POSIX有一个像 ssize_t供将为pid_t rlim_t , suseconds_t 等,这些都对基本intgral类型的所有变化。怎么可以在一个可移植的格式字符串使用这些类型?

Is there an analogous set of macros for Posix? Posix has tons of opaque types like ssize_t, pid_t, rlim_t, suseconds_t, etc, which are all variations on the basic intgral types. How can one portably use those types in format strings?

推荐答案

在了sfio包(AT&功放的一部分; T实验室'开源AST软件)具有类似于printf和scanf函数功能,这让你指定数值的大小(通常使用的sizeof())作为附加参数。一些例子:

The sfio package (part of AT&T Labs' open source AST software) has functions analogous to printf and scanf which let you specify the size of the numeric value (typically using sizeof()) as an additional parameter. Some examples:

sfprintf(sfstdout, "%I*d", sizeof(intval), intval);
sfscanf(sfstdin, "%I*f", sizeof(fltval), &fltval);

USENIX纸:扩展数据格式使用SFIO

这篇关于请问Posix的供应格式字符串宏的printf / scanf的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆