printf format specifiers for uint32_t and size_t

c, printf

Solution

Sounds like you're expecting `size_t` to be the same as `unsigned long` (possibly 64 bits) when it's actually an `unsigned int` (32 bits). Try using `%zu` in both cases.

I'm not entirely certain though.

Problem

I have the following ``` size_t i = 0; uint32_t k = 0; printf("i [ %lu ] k [ %u ]\n", i, k); ``` I get the following warning when compiling: ``` format ‘%lu’ expects type ‘long unsigned int’, but argument has type ‘uint32_t’ ``` When I ran this using splint I got the following: ``` Format argument 1 to printf (%u) expects unsigned int gets size_t: k ``` Many thanks for any advice,

Original source

Related problems