One of the problems I encounter when trying to use typedef'd variables in C is figuring out what the actual primitive type is that has been typedef'd so I can use the appropriate the % specifier when trying to print its value using printf. Most of the time I have to refer to the warnings produced by gcc. For example, when using the stat system call, the struct returned has lots of members with different typedef'd types like dev_t, ino_t, mode_t, etc, and I usually have to guess what the format specifier might be and then the compiler warns me and I correct it:
stat_demo.c: In function ‘main’:
stat_demo.c:46:45: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__blksize_t’ {aka ‘long int’} [-Wformat=]
46 | printf("block size for file system IO: %d\n", s->st_blksize);
| ~^ ~~~~~~~~~~~~~
| | |
| int __blksize_t {aka long int}
| %ld
Is this the way most people work with typedefs when printing them ? Doesn't this defeat the point since you need to know what the actual primtive being typedef'd is? Is there a better way where the actual type is completely abstracted ?