C++/CLI only way to use C++ for .NET?

A

Andreas Schmitt

Hi,

I am working on a small fun programming project (AntMe if anyone knows
it) which provides code examples for C# and Visual Basic 2005

After doing some programming with C#, I was going to try to write a
library for it with C++ too.
I never worked with .NET before only with plain C++ so I tried to find
some information about it. The only thing I found on the net are
references to Managed C++ and its successor C++/CLI.

Did I interpret the information I found on the net correctly that there
is no way to programm a .NET compatible assembly without the CLI syntax
extensions (or said in a different way, just by using only the C++
standard language)?
If so that confuses me a little since I've also found various sources
stating that C++ was a .NET compatible language. But from my knowledge
C++ and C++/CLI are not the same language but have some fundamental
differences.

Any information or a good link about this topic (Just googling for
C++/CLI and .NET didn't help much, too many (and unhelpful) results)
would be appreciated

Thanks
 
D

David Wilkinson

Andreas said:
Hi,

I am working on a small fun programming project (AntMe if anyone knows
it) which provides code examples for C# and Visual Basic 2005

After doing some programming with C#, I was going to try to write a
library for it with C++ too.
I never worked with .NET before only with plain C++ so I tried to find
some information about it. The only thing I found on the net are
references to Managed C++ and its successor C++/CLI.

Did I interpret the information I found on the net correctly that there
is no way to programm a .NET compatible assembly without the CLI syntax
extensions (or said in a different way, just by using only the C++
standard language)?
If so that confuses me a little since I've also found various sources
stating that C++ was a .NET compatible language. But from my knowledge
C++ and C++/CLI are not the same language but have some fundamental
differences.

Any information or a good link about this topic (Just googling for
C++/CLI and .NET didn't help much, too many (and unhelpful) results)
would be appreciated

Andreas:

In VS2005 you must use C++/CLI to target the .NET framework. You cannot
do it with standard C++.
 
G

Guest

I am working on a small fun programming project (AntMe if anyone knows
it) which provides code examples for C# and Visual Basic 2005

After doing some programming with C#, I was going to try to write a
library for it with C++ too.
I never worked with .NET before only with plain C++ so I tried to find
some information about it. The only thing I found on the net are
references to Managed C++ and its successor C++/CLI.

Did I interpret the information I found on the net correctly that there
is no way to programm a .NET compatible assembly without the CLI syntax
extensions (or said in a different way, just by using only the C++
standard language)?
If so that confuses me a little since I've also found various sources
stating that C++ was a .NET compatible language. But from my knowledge
C++ and C++/CLI are not the same language but have some fundamental
differences.

Any information or a good link about this topic (Just googling for
C++/CLI and .NET didn't help much, too many (and unhelpful) results)
would be appreciated

Hi,

C++/CLI is a superset of C++, just like C++ itself is a superset of C.
C++ is still a native only language. C++/CLI allows you to write .NET apps,
as well as apps that mixe native code and .NET code in the same module.

Managed C++ is the predecessor to C++/CLI. It is dead -rightfully so I might
add- and will be all but a bad dream in the near future.

There is an interesting rationale behind a lot of the C++/CLI design
decisions that can be found here: www.gotw.ca/publications/C++CLIRationale.pdf
It is written by Herb Sutter, the main man behind the C++ front end.
 
B

Ben Voigt

Any information or a good link about this topic (Just googling for C++/CLI
and .NET didn't help much, too many (and unhelpful) results) would be
appreciated

..NET assemblies carry metadata that is required for other .NET languages to
use the types and functions inside. This metadata is created only when the
C++/CLI extended syntax is used. For example, .NET requires every type to
be marked as either pass-by-value (stack and embedded variables) or
pass-by-reference (garbage collected), and native C++ syntax doesn't
indicate to the compiler which you desire.

So:
(1) The only C++ compiler capable of writing out a .NET assembly is
currently MS Visual C++ using the /clr format.
(2) /clr works with ISO standard C++ programs (commonly called native C++)
to produce .NET assembly files, but these will be missing the metadata, so
the .NET assembly cannot be usefully referenced by any other .NET program
(even C++).
(3) Using C++/CLI keywords such as "ref class" provides the compiler with
the additional information needed to produce the metadata. It also subjects
those parts of your code to the additional constraints placed on .NET types
(single inheritance, for instance).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top