Can you use C ++ and C # using C programming?

3

If I put a code for a sotfware and this code wants to use the C, C ++ and C # languages, could it? Even if I use a compiler that reads all three?

    
asked by anonymous 02.12.2016 / 14:51

1 answer

5

No compiler reads the three, even those working with C and C ++, or compile C or compile C ++.

If you're compiling C ++, almost anything you do with C syntax will work because the language was specified like this. But it is not always the ideal.

What you can do is to use 3 compilers and link all together. In the case of C #, the linking of the C or C ++ part can only be done dynamically at the moment. But that should change soon.

Calling C-code in C # is relatively easy. C ++ is not. In general you need to make a "glue" layer between native C ++, with C #. This is written in C ++ / CLI which is a managed C ++ that runs on top of CLR . What you do in C # could only be called by native C ++ through this glue. Even it can be possible to do without this glue, it is not simple, it does not compensate, and only in some cases.

Calling C # code by C only gives in very specific cases where the C # code was written thinking of providing this capability.

Calling C code in C ++ is usually ok in almost every situation. The opposite is not true. And almost always will not be so simple. If you do not get it right it does not get good.

Avoid making these integrations as much as you can. If you do, do not.

    
02.12.2016 / 15:31