I use MinGW g++ compiler on Windows (gcc version 4.8.1) and I am confused with swprintf declaration
According to this reference it should be
int swprintf (wchar_t* ws, size_t len, const wchar_t* format, ...);
However when I use
swprintf(my_ws, 32, L"hello");
I get error
initializing argument 2 of 'int swprintf(wchar_t*, const wchar_t*, ...)' [-fpermissive]
Looks like size_t len
is not in the declaration. Is the reference wrong, did I miss something or is there some story behind that?
You are using a C library that is not compliant with the C99 Standard.
MinGW is a port of gcc
that uses the Microsoft C runtime library.
Microsoft had its own version of swprintf
with a different prototype before it was standardized into C99. It is a very old C library with a lot of C99 incompatibilities, for example I don't think its printf
supports %zu
for size_t
...
You should upgrade to a more recent version of MinGW if they use a more recent runtime. If not, you are going to have to use the old prototype, and live with these obsolete APIs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.