How to print a uint64_t as hex? [duplicate]

This question already has an answer here:

I’m not able to get rid of this warning:

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

In my_test.c:

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

int main(int argc, char argv[])
{
  uint64_t my_number = 0x0706050403020100;
  printf("my_number: %#018llxn", 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;
}


Source: c

Leave a Reply