【发布时间】:2017-04-06 18:26:13
【问题描述】:
从<stdint.h> 到int32_t 的格式字符串是什么?
我正在尝试打印值,但我发现我应该使用的是:
("... %" PRId32 "...\n", value)
来自<inttypes.h>,但我得到的只是通常的“format %d expects argument of type int, but argument 2 has type int32_t”消息。
#include <stdint.h>
#include <inttypes.h>
int32_t variable = 99;
printf("Value: %" PRId32 "\n", variable);
常规格式字符串不适用于它。那么我可以使用哪种格式字符串呢?
编辑1:由于有很多误解,我已经编辑了它;我已经包含了两个标题。
编辑 2:添加实际功能(省略包含和动态分配;其中的所有内容都将被分配):
struct stuff {int32_t * array[3];}
printf("Value: %" PRId32 "\n", stuff->array[0]);
编辑 3:就像那样,错误是完全不同的。 array 前面不应该有 *。
【问题讨论】:
-
您使用的是什么平台和编译器?
-
添加这个:
#include <inttypes.h> -
@Arash 当我看到你的评论进来时,我想开始写这个作为答案。这是解决方案:ideone.com/OlOY0r
-
我不是 100% 相信这是解决方案:ideone.com/RoTgpv
-
struct stuff {int32_t * array[3];} printf("Value: %" PRId32 "\n", stuff->array[0]);不是有效的 c 代码,原因有很多。多次向 OP 请求完整的代码,并且只跟进了不可编译的 sn-ps。不清楚为什么 OP 没有发布清晰的问题代码示例。
标签: c