I want to write some library code to be shared across products and across platforms, including OS X and .Net.
My current research suggests that writing this core library code in C++ is a good approach. Obviously I could also use Java but it’s not my strong suit – I’d rather stick with ObjC / C++ / C# where I can.
I believe that C++/CLI is the current choice for C++ in .Net so my question is; is C++/CLI a strict superset of ‘vanilla’ ISO C++? In other words if I write C++ code that compiles under gcc, for example, can I compile that without change (or with a few conditional compiles) under C++/CLI?
Obviously I will have to write wrappers around system functions, I/O etc. – that’s fine – but I want the core algorithmic code to be as portable as possible.
In most cases, but not necessarily. For example, the STL/CLR is hideously slow in comparison to the BCL, and some things like nullptr refer to the managed nullptr, not the native nullptr. Even if your app compiled cleanly for .NET, that doesn’t make it the right thing to do.
It would be much more reasonable to compile the native side to a DLL and then P/Invoke from C# if you must offer a managed interface. This will be much more reliable.