0

I struggle with the correct format specifier in C.

I am working with a 32-bit uC and I am using %lu for type uint32_t. For uint8_t I am using %u. That works fine.

What I can't figure out is, whether I have to use %lu or %u for uint32_t when I am dealing with a 64-bit address with uC. And the other way around: is %lu the correct format specifier when I use type uint32_t on a 16-bit system? Or should the format specifier be %llu instead?

Is the format specifier dependent on the system I am working with?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
usr
  • 1
  • [How do I print uint32_t and uint16_t variables' value?](https://stackoverflow.com/q/12120426/995714), [nt32_t and printf format: %d or %ld?](https://stackoverflow.com/q/40121748/995714) – phuclv Dec 21 '21 at 17:41
  • So to clarify for you: The types are there exactly because the incantation needed for getting an int of the desired bit-width, is system/platform specific. Hence you need to do something "clever" to mean "32 bit" or something else on your system. This is what the answers show you how to do... – S.C. Madsen Dec 21 '21 at 18:26
  • 1
    " I am dealing with a 64-bit address" --> Do not use any _integer_ print specifier. Use a `printf("%p\n", (void*) address);`. – chux - Reinstate Monica Dec 21 '21 at 18:51

0 Answers0