3
If I build a code for a sotfware and want to use the C, C++ and C# languages could I? Even if I use a compiler that reads all three?
3
If I build a code for a sotfware and want to use the C, C++ and C# languages could I? Even if I use a compiler that reads all three?
6
No compiler reads all three, even those working with C and C++, or compiles C or compiles C++.
If you are compiling C++, almost everything you do with C syntax will work because the language has been specified like this. But it is not always ideal.
What you can do is use 3 compilers and link all together. In the case of C#, at the moment the linking of the part in C or C++ can only be done dynamically. But this should change soon (happened with limitations).
Calling C code in C# is relatively easy. C++ is not. In general you need to make a layer of "glue" between the native C++ with C#. This is written in C++/CLI which is a managed C++ that runs on top of the CLR. What you do in C# could only be called by the native C++ through this glue. It might even be possible to do without this glue, it’s not simple, it doesn’t pay, 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. But this is improving.
Calling C code in C++ is usually ok in almost every situation. The opposite is not true. And almost always won’t be so simple. If you don’t do it right, it’s not good. But it works.
Avoid doing these integrations as much as you can. If you have a choice, do not.
Browser other questions tagged c# c c++
You are not signed in. Login or sign up in order to post.
C and C++ "can" and C# is another story...
– MagicHat
C# is a C dialect but is managed (uses the .NET framework). You will not find a compiler that uses C++ and C# because, internally, they are very different things. Remember that there are several C dialects, including JAVA is based on C. C# can be compared to JAVA (in terms that the two are managed and generate an IL) but not to C++.
– William John Adam Trindade
You can call things done in C / C++ inside C#, but then it’s already Unmanaged code, is not portable and has a number of consequences. Easier you explain better than you need, to increase the accuracy of possible answers. In other words, you can mix the three things, but it’s rare that someone needs it for real.
– Bacco
@Williamjohnadamtrindade C# is not a dialect of C. Java so it goes much further. This information is very wrong. If the question has more details, as Bacco said, I can still improve the answer
– Maniero
@bigown What does Voce consider a dialect? C# does have its roots in C++ as well as Java has its roots in C++ as well.
– William John Adam Trindade
@Williamjohnadamtrindade Dialect is a small variation of language. C# is completely different from C. A small, equal syntax feature has been adopted and stays with it. Within what is spoken almost all languages and everyone calls them languages, and not dialects, would be dialects of C because they have one or the other characteristic of C. nor is C++ dialect of C, is almost a superset. C# tried to take advantage of some of the little things in C++. Java passed away, deliberately I chose not to follow this path. It’ll get too long to just comment on everything.
– Maniero
@bigown I consider as dialect those languages that have the same syntactic basis. See the list of languages that are part of the C-family: https://en.wikipedia.org/wiki/List_of_C-family_programming_languages
– William John Adam Trindade
Then everything would be dialect, you consider and be in fact are different things. Being of the same family is far from being of the same dialect. Portuguese BR or PT are dialects. Portuguese, Spanish, French, Italian, Romanian are from the same family. You don’t think family is family, it’s gotta be a higher level, but I’m not a linguist. Note that you don’t have a definition of what a family of programming languages is, that’s something someone wrote, but formally I don’t know this taxonomy and its criteria. I believe it is having keys and a semicolon. That’s it!. This is too little to put everything in the same basket.
– Maniero
@Williamjohnadamtrindade read the headline saying that many people consider it wrong.
– Maniero
@bigown Actually adding PHP as a member of the C family is forcing the bar, but at least Voce agrees syntactically that JAVA and C# use the syntax defined in C?
– William John Adam Trindade
@Williamjohnadamtrinity very little.
– Maniero