bummer.
I just did some testing on linux and it has become a bit difficult to create portable printf format strings.
We now have good portable types in <stdint.h> and now there are some portable printf format helper types/macros in <inttypes.h> but they are clunky.
Then there are somewhat hidden types that are inconsistent across implementations
Example, size_t and sizeof()
There is no way to know what size these are. (sizeof() now returns a size_t instead of an int)
Combine that with int and long int can be the same size and it starts to become difficult to write truly portable code.
IMO, the printf() format checking is a bit broken as it is being too strict since it reports an issue for int vs long int when they are the same size.
IMO, if they are the same size and the same signedness, then they are functionally the same so there should be no warning since they would be both be interpreted the same, and formatted the same.
i.e. there is no stack frame issue since the two types are functionally the same.
Maybe this is actually an issue that could/should be solved with <stdint.h> ?
since if int and long int are the same then uint32_t could have been defined as unsigned int instead of a long unsigned int.
There is no simple/easy answer since implementations can define things differently and behave differently.
The only way to handle it is to use the format helper macros in <inttype.h> whenever types from <stdint.h> are used.
For example:
Code:
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
uint32_t u32x = 1;
uint64_t u64x = 1;
int main(int n, char *argv[])
{
printf("uint32_t var : %"PRIu32"\n", u32x);
printf("uint64_t var: %"PRIu64"\n", u64x);
}
but it is clunky.