I'm writing a c++ library that exposes some functions which are used only by C# code. However, as I accidently mistyped the paramter, I found that this code can be succesfully compiled and linked even without any warning as long as I don't use the (not mistyped version) function in the cpp file.
struct Dummy { int a; double b; };
extern "C" void SetArray(Dummy* x, int cnt);
void SetArray(Dummy x, int cnt)
{
// a TODO placeholder.
}
How can I let compiler throw an error or a warning for this case? The compiler option -Wall is set but there's still no warning. Using tdmgcc 5.1.0.
So, if he knows this code (theoretically) and there is some inherent danger in overloading, then he should know this already because he knows the code. That said, overloading cannot be stopped as others have already described.
Not any C-header can be made compatible with C++ by merely wrapping in extern "C".
This feature is present in most of the Object Oriented Languages such as C++ and Java. But C doesn't support this feature not because of OOP, but rather because the compiler doesn't support it (except you can use _Generic). However, one can achieve the similar functionality in C indirectly.
You can make some assertion that will fail if function is overloaded:
static_assert(::std::is_same_v<void (Dummy *, int), decltype(SetArray)>);
error: decltype cannot resolve address of overloaded function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With