You can make a macro
#define STR2(STR) (int const){ (STR).l }, (char const*const){ (STR).s }
and then use this as printf("%.*s\n", STR2(str)) .
Beware that this evaluates to STR twice, so be careful with the side effects, but you probably already knew that.
Edit:
I use complex initializers, so these are implicit conversions. If everything goes wrong, there is more chance that the compiler will warn you than with an explicit cast.
For example, if STR has a .l field that is a pointer, and you just put the cast in int , all compilers would happily convert that pointer to int . Similarly, for the .s field, it really should match char* or something compatible, otherwise you will see a warning or error.
source share