0

I am running OpenSuse on Oracle Virtual Machine and I get this kind of error when I compiled my code :vir

warning: format '%lx' expects argument of type 'long unsigned int', but argument has type 'uint64_t' Casting value did not help.

The code runs and compiles great on another OpenSuse laptop, I know that OS on virtual machine doesn't have the exact same behavior of 'normal boot' OS, but do you know which fix I can do to solve this problem ?

Seki
  • 11,135
  • 7
  • 46
  • 70
Jean
  • 1,707
  • 3
  • 24
  • 43
  • Possible duplicate of http://stackoverflow.com/questions/9225567/how-to-print-a-int64-t-type-in-c. Not sure where `u_int64_t` is from, but it probably has the same representation as `uint64_t`. – Ulfalizer Apr 30 '15 at 07:20
  • 1
    It's probably a "bitness" problem of the guest OS, i.e. 32-bit vs. 64-bit. Virtual machines get no special treatment from the compiler. – Hristo Iliev Apr 30 '15 at 07:21
  • Sorry I use a wrong name, I edited my question. I will look at your link, thank you. – Jean Apr 30 '15 at 07:21
  • 3
    You should use a correct [format macro constant](http://en.cppreference.com/w/c/types/integer#Format_macro_constants), in your case `PRIx64`. See an [example](http://en.cppreference.com/w/c/types/integer#Example) on how to use those macros. – Some programmer dude Apr 30 '15 at 07:23
  • I'm not sure : I use SCNx64 format for sscanf and I get these errors too. @HristoIliev My code originally run on 64 bits, and now the VM is on 32 bits, so that's should be it does not work. I avoid errors printf errors by casting with (long), but I still have sscanf errors. 'sscanf(string,"%4" SCNx16, &uint16_t_value)' – Jean Apr 30 '15 at 07:40
  • 4
    The problem is you are assuming `long unsigned int` to be the same type as `uint64_t`, but that's not true on 32-bit Unix systems where the 64-bit integer type is `long long`. – Hristo Iliev Apr 30 '15 at 07:49

1 Answers1

0

As per section 7.8 Format conversion of integer types <inttypes.h> of the ISO (C11) standard, there are specific format specifiers for the specific-width-integer types defined in stdint.h (such as uint64_t):

The header <inttypes.h> includes the header <stdint.h> and extends it with additional facilities provided by hosted implementations.

A little further on from that, in 7.8.1 Macros for format specifiers, it starts detailing the format specifiers you should use.

For the uint64_t type, the lower case hex output format is PRIx64, so you should be using something like:

printf ("The value is %" PRIx64 "\n", myUint64tVariable);
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953