printf, wprintf, %s, %S, %ls, char* and wchar*: Errors not announced by a compiler warning?

前端 未结 6 2021
自闭症患者
自闭症患者 2020-12-02 23:29

I have tried the following code:

wprintf(L\"1 %s\\n\",\"some string\"); //Good
wprintf(L\"2 %s\\n\",L\"some string\"); //Not good -> print only first char         


        
6条回答
  •  长情又很酷
    2020-12-02 23:48

    I suspect GCC (mingw) has custom code to disable the checks for the wide printf functions on Windows. This is because Microsoft's own implementation (MSVCRT) is badly wrong and has %s and %ls backwards for the wide printf functions; since GCC can't be sure whether you will be linking with MS's broken implementation or some corrected one, the least-obtrusive thing it can do is just shut off the warning.

提交回复
热议问题