Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "compatibility for C++ mangling"?

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?

like image 865
Igor Liferenko Avatar asked Dec 24 '22 23:12

Igor Liferenko


1 Answers

So here's some relevant definitions:

  • ABI: Application Binary Interface
  • Name Mangling

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.

like image 136
robert Avatar answered Dec 28 '22 07:12

robert