I just learned about C, and
I know this is a basic question, but I just can not figure out how I can solve this. For instance, I have a line of
printf("value :%d\n",var.value);
the format does not suit, as it shows error below
*format ‘%d’ expects type ‘int’, but argument 3 has type ‘uint32_t *’
I have already checked at this reference of cplusplus : cplusplus print ref
but it does not explicitly state how to print the value with the type is uint32_t * (likewise uint16_t).
Any explanation will very appreciated.
You were trying to print a pointer to an uint32_t as an int.
You have to do two things:
The correct way to format an uint32_t is to use the macro
PRIu32, which expands to the format character as a string.That is, you do
You’re probably on a common platform where an unsigned int is the same as uint32_t, in which case you could just do:
(note, %u instead of your code that used %d , %u is for an unsigned int, while %d is for a signed int)