ソースコード:
const wchar_t* x = L"abc";
printf("%d\n",wcslen(x));
これを でコンパイルした結果g++ -fshort-wchar xxx.cpp -o xxxが得られます。15なんで?
gcc のドキュメントでは次のように警告されています。
*Warning:* the `-fshort-wchar' switch causes GCC to generate code
that is not binary compatible with code generated without that
switch. Use it to conform to a non-default application binary
interface.
おそらく、wcslenリンク先の は通常の長さwchar_tの s で生成されたものであり、その結果、 が見つかるまでカウントされます(regular_wchar_t)0。L"abc"short で生成されたwchar_tは通常の で終了しないwchar_tため、wcslenランダム メモリが見つかるまで実行され続けます。