如何将uint64_t打印为十六进制?

时间:2015-05-30 08:12:53

标签: c hex printf uint64

我无法摆脱这个警告:

warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’ [-Wformat=] printf("my_number: %#016llx\n", my_number);

在my_test.c中:

#include <stdint.h>
#include <stdio.h>

int main(int argc, char argv[])
{
  uint64_t my_number = 0x0706050403020100;
  printf("my_number: %#018llx\n", my_number);

  return 0;
}

ANSWER

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

int main(int argc, char argv[])
{
  uint64_t my_number = 0x0706050403020100;
  printf("my_number: %#018" PRIx64 "\n", my_number);

  return 0;
}

0 个答案:

没有答案