Reputation: 1911
In the C++/CLI project I have the method void DoSomething(long x);
. If I want to use it in any unit-test written in C#, the method parameter x
shows up as type int
.
Why do I have to change the signature to void DoSomething(long long x);
to use it with parameters of type long
in my unit-tests (C#)?
Upvotes: 2
Views: 3207
Reputation: 941635
long
is a keyword both in C# and C++. They simply don't mean the same thing. The C++/CLI designers went for the C++ interpretation since C++ was the target interop language.
Not exactly the only unintuitive mapping:
Beware the required public
keyword for an enum, a necessary evil since C++11 adopted the enum class
syntax.
Only the void, bool, short, int, float and double keywords match.
Upvotes: 10
Reputation: 180660
In C# long
is a 64 bit data type. In C++ All we know about long
is that it has to hold as much or more than an int
and it is at least 32 bits. If you use a long long
in c++ that is guaranteed to be at least 64 bits which will match what you have in C#.
Upvotes: 7