[英]Printing uint64_t* value in C
我正在使用以下代碼:
size_t offset = (rand() << 12) % chunk_size;
uint64_t *addr = (uint64_t*) (chunk+offset);
fprintf(stdout,"addr: %" PRIx64 " ", addr);
我包含了<inttypes.h>
庫,但出現以下錯誤:
error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t *’ {aka ‘long unsigned int *’} [-Werror=format=]
fprintf(stdout,"addr: %" PRIx64 " ", addr);
uint64_t * {aka long unsigned int *}
In file included from filename.c:5:
/usr/include/inttypes.h:121:34: note: format string is defined here
121 | # define PRIx64 __PRI64_PREFIX "x"
cc1: all warnings being treated as errors
make: *** [Makefile:8: filename.o] Error 1
為什么?
謝謝你。
問題是您要打印的類型是uint64_t *
而不是uint64_t
,因此如果要打印指針( addr
),只需在printf
使用%p
,否則您需要使用*
取消引用指針。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.