druntime icon indicating copy to clipboard operation
druntime copied to clipboard

set WCHAR to wchar_t for future

Open WalterBright opened this issue 6 years ago • 8 comments
trafficstars

Part of transition to C++11 types. Blocked by https://github.com/dlang/dmd/pull/9029

WalterBright avatar Dec 02 '18 23:12 WalterBright

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + druntime#2390"

dlang-bot avatar Dec 02 '18 23:12 dlang-bot

What does C++11 compatibility have to do with the Windows API? The Windows API is all C and does not use type mangling. Is it for non-Windows C++ APIs which use Windows API types?

CyberShadow avatar Dec 02 '18 23:12 CyberShadow

What does C++11 compatibility have to do with the Windows API?

Microsoft changed the definition of WCHAR to wchar_t. Meaning D cannot connect to C++ code that uses WCHAR. It'll get worse with increasing use of char16_t.

WalterBright avatar Dec 03 '18 04:12 WalterBright

They didn't 'change' the definition of WCHAR to wchar_t, that's just how it is for C++. For C, it's defined as unsigned short. It's always been this way.

TurkeyMan avatar Dec 03 '18 06:12 TurkeyMan

Right, and for C it doesn't matter anyway because there is no mangling.

thewilsonator avatar Dec 03 '18 06:12 thewilsonator

And for MS code, it just so happens that wchar_t matches unsigned short, and also that WINAPI is extern(C), not C++... but the type definitions and value of the macros has never changed.

TurkeyMan avatar Dec 03 '18 06:12 TurkeyMan

Right, and for C it doesn't matter anyway because there is no mangling.

Right, but there is a gotcha case, which MS have a hack to deal with; back in the old days, when programmers wrote C and WCHAR was unsigned short, other developers would write compatible API's, but they would use unsigned short in their API's that received strings (because they didn't want to #include <windows.h> to get WCHAR... so there are/were a lot of string API's that used unsigned short explicitly instead of WCHAR, and then when those C API's were compiled with a C++ compiler, there were linkage problems, so VC++ has a hack to mangle WCHAR as unsigned short. It's wrong, but the hack exists.

It's all old deprecated junk though, we shouldn't bother ourselves with any of that history.

TurkeyMan avatar Dec 04 '18 00:12 TurkeyMan

we shouldn't bother ourselves with any of that history

Indeed, microsoft explicitly recommend against using that flag.

thewilsonator avatar Dec 04 '18 00:12 thewilsonator