How to use stdint types with _tprintf in Visual Studio 2013?

Take the following example:

char* fileName = "C:\\windows\\system32\\kernel32.dll";
uint32_t fileSize = 1163264;
printf("The size of %s is %"PRIu32"\n", fileName, fileSize);

Everything is all right, now if we want transparent unicode support through tchar.h, the code would look like this:

TCHAR* fileName = _T("C:\\windows\\system32\\kernel32.dll");
uint32_t fileSize = 1163264;
_tprintf(_T("The size of %s is %")_T(PRIu32)_T("\n"), fileName, fileSize);

This works if unicode has no . However, if unicode is defined, the compiler breaks with the following error:

error C2308: concatenating mismatched strings
Concatenating wide "The size of %s is %l" with narrow "u"

Now let's look at Microsoft inttypes.h I see:

...
#define _PFX_32  "l"
...
#define PRIu32       _PFX_32 "u"

This means that _T(PRIu32)in the example above it resolves:

_T("l" "u")

... which cannot work, of course, and explains the correct compiler error.

So my question is, how did Microsoft suggest that we use their inttypes.h with _tprintf?

+4
1

1 C, ( : ) , , , .

_T. , UNICODE , L .

_T , , :

_tprintf(_T("The size of %s is %") PRIu32 "\n", fileName, fileSize);

Visual Studio, , C99, . , Visual Studio 2015.

2 .


1 ( : ISO/IEC 9899: 201x 6.4.5 5)
6 , - . - , ; . - - , , .

2 ( : ISO/IEC 9899: 201x 7.8.1 7)
wprintf(L"The largest integer value is %020" PRIxMAX "\n", i);

+3

Source: https://habr.com/ru/post/1663647/


All Articles