English 中文(简体)
Is it difficult to port C++ to C++/CLI?
原标题:
  • 时间:2009-11-20 14:17:35
  •  标签:
  • c++
  • c++-cli

I suppose you cannot simply compile a C++ application with a C++/CLI compiler. I am wondering if it would be difficult. Has anybody tried this, and if so: were there a lot of modifications needed?

最佳回答

The situation is a bit like compiling C as C++. Most C will compile as C++, but is a long ways from what you d think of as exemplary C++, so chances are that you d want to modify it (often quite a bit) before you used it.

Likewise, most C++ will compile as C++/CLI, but chances are that you d rather not really use it that way.

问题回答

This will work well for almost any native C++ code. It will get translated to IL, just like managed code, and get JIT compiled at runtime. You can freely call managed code, thanks to C++ interop. The only unmanaged code construct I know that can t be compiled is the __fastcall keyword. There s an issue with the const keyword, it is imperfectly simulated with attributes, but that s only an issue when you import metadata. Just keep using header files like you do now.

A .NET assembly is capable of storing machine code as well as IL. You can take advantage of this by selectively turning off IL generation for cases where the compiler has trouble or when you suspect generated code isn t optimal. Wrap your code with a #pragma:

#pragma managed(push,off)
void CompiledToMachineCode() {
  // etc..
}
#pragma managed(pop)

You will also need to use this #pragma when you #include headers for .libs that were compiled separately without the /clr compile option.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签