5

wint_t type is set inside wchar.h via stddef.h, using the fact that __WINT_TYPE__ is already defined in the compiler by default. So to change

typedef unsigned int wint_t;

into

typedef wchar_t wint_t;

we may use the following code in the beginning of wchar.h

#undef __WINT_TYPE__
#define __WINT_TYPE__ wchar_t
#define WEOF (-1)

But this comment suggests that doing this "breaks compatibility for C++ mangling".

You can't change existing definitions of typedefs such as wint_t without breaking ABI compatibility (even when you have the same size and signedness and so are ABI-compatible for C, changing the underlying type breaks compatibility for C++ mangling).

So, why exactly this typedef cannot be changed and what is "compatibility for C++ mangling"?

See also this question How to change wchar.h to make wchar_t the same type as wint_t?

Community
  • 1
  • 1
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
  • In C++, `wchar_t` is a separated type – Danh Nov 21 '16 at 09:53
  • That said, functions with C linkage don't include types in the mangling, so I'm not entirely sure how such a change could affect anything C++ related. See also [diff.wchar.t]; no such typedef would be exposed to C++. – Kerrek SB Nov 21 '16 at 09:55

3 Answers3

6

So here's some relevant definitions:

Name mangling is the way that the compile represents the method-names you define in C++ so that they're qualified "per class" so for instance ClassA::method() doesn't clash with ClassB::method() - this also facilitates overloading such that ClassA::method(String s) doesn't clash with ClassA::method(int i).

Internally these might be represented something like ClassA_method, ClassA_method^String, ClassA_method^int

As the second topic above discusses "name mangling is not merely a compiler-internal matter" - in cases where a public interface for a shared library is being generated, for instance.

So if you take a typedef and change it for your own code, it'll be okay for all the binaries you generate, but any pre-existing binaries such as 3rd party DLLs that depend on this typedef will break.

robert
  • 4,612
  • 2
  • 29
  • 39
3

Another case where mixing C and C++ hurts you. The question only makes sense in the non-existent "C/C++" language.

In C, name mangling is rare, and for standard ABI's does not include type names. Hence, it doesn't matter what wchar_t's real name is.

In C++, wchar_t is not a typedef.

MSalters
  • 173,980
  • 10
  • 155
  • 350
2

I assume you know what mangling is. If not a good explanation is here.

I also assume that by compatibility it means that it has to do with various compilers. I know that certain ARM compilers such as Keil handle certain things differently than standard GCC and Clang on desktop/server when it comes to name mangling.

That would be normally also documented like this.

By changing a certain type on your own, you can break a compiler default mapping for name mangling on a certain system.

mutantkeyboard
  • 1,614
  • 1
  • 16
  • 44