Suppose I need to print a formatted string with an int32_t
using the printf format specifier from
.
int32_t i = 0;
pr
The problem is twofold. First, as noted in rici's answer, C99 and C++11 both added support for concatenating narrow string literals and wide string literals together, so you should not need to widen the narrow literal by prepending the L. Visual C++ does not yet support this feature for either C or C++.
Because the compiler does not yet support this feature, we should in the libraries make it possible for you to explicitly widen these string literals using a technique like the one in your answer. Unfortunately, we've defined these macros in a way such that they may expand to multiple string literals. E.g., PRId32
expands to "l" "d"
.
This is valid, but it does prevent you from widening, because there is no way to prepend an L
to the second string literal (to make "d"
into L"d"
). I'm afraid I don't see a way to make this work without (re)defining the macros yourself.
I've opened a bug internally so that if the compiler does not add support for concatenation of mixed-width literals during preprocessing in the next release, we can revisit these definitions to possibly make it possible to widen them explicitly.