13

Would a C++ CLI compiler be able to compile some large sets of C++ classes without modifications?

Is C++ CLI a superset of C++?

5
  • 2
    I was confused by this question at first, then I found out that "CLI" here stands for Common Language Interface (part of .net) and not Command Line Interface. Namespace collision!
    – Neall
    Oct 8, 2008 at 15:41
  • 1
    Sorry - "Common Language Infrastructure" - en.wikipedia.org/wiki/Common_Language_Infrastructure
    – Neall
    Oct 8, 2008 at 15:42
  • Yeah, my first thought was Command Line Interface. I thought, Cool! A VMS question!
    – Vagrant
    Jun 3, 2010 at 8:04
  • @Vagrant just wondering...what is a "VMS" question? Jul 19, 2012 at 20:50
  • @hrishikeshp19 Virtual Memory System perhaps. ☺
    – IS4
    Dec 21, 2012 at 22:36

6 Answers 6

10

According to Wikipedia:

C++/CLI should be thought of as a language of its own (with a new set of keywords, for example), instead of the C++ superset-oriented Managed C++

5
  • Although even most of the new keywords are contextual and can be used as identifiers in other code.
    – Eclipse
    Jan 20, 2009 at 20:08
  • There are three unconditional keywords, gcnew, generic and nullptr. The last one is now also a C++ keyword. So the amount to which C++/CLI fails to be a superset of C++ is really fairly small...
    – Kerrek SB
    Sep 2, 2012 at 21:42
  • @KerrekSB I know the point was that it isn't technically a superset (which this doesn't change) but couldn't you do this to make it compile? #define gcnew gcnew_identifier #define generic generic_identifier // paste incompatible C++ code (or include directives) here #undef gcnew #undef generic (Yes it's ugly, but I'm not going to worry about it because it's not my fault Stack Overflow decided to remove the line breaks.)
    – Sparkette
    Sep 19, 2019 at 17:46
  • @flarn2006: As always, if you define a macro with a reserved name, such as the name of a keyword, all bets are off. What if your C++ code calls into a standard library facility that internally wants to use those keywords? A simpler and more robust solution would be to simply scan your C++ code for the problematic identifiers and rename them. Standard C++ already has the same issue whenever new language versions add keywords. As far migration issues go, this is among the easiest to solve.
    – Kerrek SB
    Sep 19, 2019 at 21:07
  • And as long as your interfaces don't contain problematic names, you could also perhaps compile the C++ code as C++, and then link it with the C++/CLI code? I think C++/CLI was meant to work in such a bridging role. (But I think it's pretty much dead by now anyway.)
    – Kerrek SB
    Sep 19, 2019 at 21:09
4

technically no, but depending how standard the C++ code is, you'll probably be just fine. when you get into windows stuff you may run into issues. I compiled the whole game engine we use at work in C++/CLI once and it worked just fine. A colleague did the same for all of mozilla and no such luck.

2

I'm still new with my learning curve on C++/CLI -- but I've had the same question myself, and what I've determined so far is that C++/CLI is, as a language, a superset of standard C++.

If you don't use the CLI extensions, your C++ code will end up as native unmanaged code, and should be essentially the same, but compiled to the CLR IL, instead of native x86.

Once you start using the CLI extensions (and start falling into the use of objects/handle/managed classes), you start interacting with the underlying CLR platform more heavily. At that point, it essentially becomes a new "language", and you'll have to separate your thinking between the "unmanaged" side and the "managed" side.

2

C++/CLI is not a superset of C++. It rather is a subset with additions. E.G. C++/CLI does not support multiple inheritance.

Angelo

4
  • No multiple inheritance? Where did you see this?
    – Gabe
    Oct 24, 2010 at 1:20
  • In the documentation? All CLI languages only support single inheritance. However perhaps you can do MI with unmanaged code, never checked that. Oct 24, 2010 at 14:17
  • Hm, I read up on wikipedia a bit. I did not catch that C++/CLI "replaced" Managed C++. Unfortunately the Wikipedia article is not stating under wich circumstances C++/CLI supports MI. Oct 24, 2010 at 14:35
  • 3
    C++/CLI supports multiple inheritance of class types perfectly well, just like ISO C++. It doesn't support multiple inheritance of managed types, but then again neither does ISO C++.
    – Ben Voigt
    Mar 15, 2011 at 17:16
1

Page 3 of Marcus Heege's book 'Expert C++/CLI.NET for Visual C++ Programmers' states:

C++/CLI is a set of extensions made to the C++ language to benefit from the services that an implementation of the CLI offers.

And further down the same page:

C++/CLI is a superset of the C++ language.

His excellent book is available for free from here.

2
  • 4
    Looks like the book is wrong. See stackoverflow.com/questions/4610671/… Jan 6, 2011 at 0:43
  • 1
    Quoting authority Herb Sutter: "As for whether this set of extensions amounts to a different superset language, a compatible dialect, and/or a binding: I think you can find reasonable people who view it any of those ways. Whichever noun you prefer, it is the most compatible set of extensions I know of to any programming language, standard or otherwise [...]" - See A Design Rationale for C++/CLI, Version 1.1 — February 24, 2006.
    – Lumi
    Dec 14, 2011 at 22:14
1

I was able to compile whole Qt library (which is huge) as C++/CLI with minor modifications (mostly in the build environment, but also fixed one bug in Qt source code)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.