C++/CLI experiments

I

Ioannis Vranos

OK, I just installed the tools refresh in VC++ 2005 Express Beta1, and
now it can indeed be called a Beta.

I decided to check the ref types on stack thing, and after some seconds
of effort I came to this:



int main()
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}



C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>temp


C:\c>


==> It doesn't print "Hello world".



Questions on the above:

The String object created above is equivalent to new String("Hello World")?

Why it doesn't print anything?






Best regards,

Ioannis Vranos
 
T

Tomas Restrepo \(MVP\)

Ioannis,
OK, I just installed the tools refresh in VC++ 2005 Express Beta1, and
now it can indeed be called a Beta.

I decided to check the ref types on stack thing, and after some seconds
of effort I came to this:



int main()
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}



C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

/out:temp.exe
temp.obj

C:\c>temp


C:\c>


==> It doesn't print "Hello world".



Questions on the above:

The String object created above is equivalent to new String("Hello World")?

Why it doesn't print anything?

Ouch! Looks like a compiler bug, to me. Looking at the generated code, one
can see the compiler is loading s with null, not with the reference to the
string :(

You might want to report that....
 
D

Don Kim

int main()
{
using namespace System;

String s="Hello world";

Console::WriteLine(%s);

}

C:\c>cl /clr:safe temp.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.40809
for Microsoft (R) .NET Framework version 2.00.40607.16
Copyright (C) Microsoft Corporation. All rights reserved.

temp.cpp
Microsoft (R) Incremental Linker Version 8.00.40809
Copyright (C) Microsoft Corporation. All rights reserved.

Why it doesn't print anything?

Wierd, when I tried to compile the above, the compler complained I could not
allocate the String on the stack. I had to reference with ^.

The changes below made it compile:

#using <mscorlib.dll>

int main()
{
using namespace System;

String ^s = "Hello world";

Console::WriteLine(s);

}

- Don Kim
 
I

Ioannis Vranos

Don said:
Wierd, when I tried to compile the above, the compler complained I could not
allocate the String on the stack.


Did you install Visual C++tools refresh (for Beta 1)?

http://www.microsoft.com/downloads/...f1-9d16-439a-9a5e-e13eb0341923&displaylang=en



The changes below made it compile:

#using <mscorlib.dll>

int main()
{
using namespace System;

String ^s = "Hello world";

Console::WriteLine(s);

}



mscorlib.dll is not required in C++/CLI standard.






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Tomas said:
Ouch! Looks like a compiler bug, to me. Looking at the generated code, one
can see the compiler is loading s with null, not with the reference to the
string :(

You might want to report that....


Feel free to report it yourself. :)






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Ioannis said:
I changed my mind. I will report it now to have the fun. :)


"Error

An error has occurred during the processing of your request. Please try
again later."





Now this is funny, isn't it?






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Ioannis said:
"Error

An error has occurred during the processing of your request. Please try
again later."


OK, now that I resubmitted it with IE it worked. :)






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Tomas said:
Ouch! Looks like a compiler bug, to me. Looking at the generated code, one
can see the compiler is loading s with null, not with the reference to the
string :(

You might want to report that....


I submitted it under the subject "String initialisation bug".






Best regards,

Ioannis Vranos
 
G

Gabest

After having read several posts involving Ioannis Vranos' experiments with
the new syntax, questions raised inside me (forgive me, it's 3:29am now :).
Is transforming C++ to a new - "alien" looking - language necessary? Wasn't
C# supposed to be THE new language? In the end by how much will MC++ and C#
differ really? Because I have the feeling they won't too much, since they
are going to compile to the same code in the end, and this drives developers
of the languages towards similar design goals. Allowing many languages used
is nice idea but without having hands tied by some nasty c++ standards the
differencies between these two languages can fade away quickly. This is only
my opinion of course.
 
W

William DePalo [MVP VC++]

Gabest said:
After having read several posts involving Ioannis Vranos' experiments with
the new syntax, questions raised inside me (forgive me, it's 3:29am now
:). Is transforming C++ to a new - "alien" looking - language necessary?

IMO, that question begs another question. Is it important to you to be able
to target the .Net platform using a language a lot like, but not the same
as, ISO C++?

If your answer is "No" then C# is the way to go. If it is "Yes" then, again
IMO, you need to accept the departures from the bog standard language in
order to accomodate .Net concepts like garbage collection on which the
language is silent.
Wasn't C# supposed to be THE new language?

Umm, Yes. And it is.
In the end by how much will MC++ and C# differ really?

A lot. C# is elegant and expressive and values those attributes far more
over some level of compatibilty with an existing language. This
compatibility, is either a huge complication or a absolute necessity. :) It
all depends on how much you value the tie to C++.
This is only my opinion of course.

As all of the above is mine.

Regards,
Will
 
T

Tomas Restrepo \(MVP\)

Gabest,
After having read several posts involving Ioannis Vranos' experiments with
the new syntax, questions raised inside me (forgive me, it's 3:29am now :).
Is transforming C++ to a new - "alien" looking - language necessary? Wasn't
C# supposed to be THE new language? In the end by how much will MC++ and C#
differ really? Because I have the feeling they won't too much, since they
are going to compile to the same code in the end, and this drives developers
of the languages towards similar design goals. Allowing many languages used
is nice idea but without having hands tied by some nasty c++ standards the
differencies between these two languages can fade away quickly. This is only
my opinion of course.

I'll leave MS to answer this fully, but having done quite a bit of work with
the existing MC++ myself, I can say that C++/CLI is a step in the right
direction. The syntax is far more natural and far more powerful. C# might be
nice, but when it comes to raw power, it doesn't even come close to what
C++/CLI will offer, since it allows you access to almost all the features
that can be represented in metadata.

Also, it allows both templates and generics (even templates over ref
classes), which goes far beyond just the generics support in C#.

If you haven't already, I'd strongly suggest reading both the C++/CLI
migration guide I referenced in an earlier message, as well as all the blog
entries by Brandon Bray !(http://blogs.msdn.com/branbray) and Herb Sutter
(http://blogs.msdn.com/hsutter/).... they do a great job of explaining the
rationale for the new syntax...
 
I

Ioannis Vranos

Gabest said:
After having read several posts involving Ioannis Vranos' experiments with
the new syntax,
Where?




questions raised inside me (forgive me, it's 3:29am now :).
Is transforming C++ to a new - "alien" looking - language necessary?
No.



Wasn't
C# supposed to be THE new language? In the end by how much will MC++ and C#
differ really? Because I have the feeling they won't too much, since they
are going to compile to the same code in the end, and this drives developers
of the languages towards similar design goals. Allowing many languages used
is nice idea but without having hands tied by some nasty c++ standards the
differencies between these two languages can fade away quickly. This is only
my opinion of course.


The truth is... C++/CLI will be better than current C#.






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

William DePalo [MVP VC++] wrote:

Umm, Yes. And it is.




A lot. C# is elegant and expressive and values those attributes far more
over some level of compatibilty with an existing language. This
compatibility, is either a huge complication or a absolute necessity. :) It
all depends on how much you value the tie to C++.



I am sorry to disappoint you but you are wrong. Check these:


http://microsoft.sitestream.com/TechEd/DEV/DEV333_files/Botto_files/DEV333_Sutte.ppt


http://www.accu.org/conference/pres...Relevant_on_Modern_Environments_(keynote).pdf



Read that C++/CLI is usually 25% faster than C# for pure .NET code and
that C++/CLI is correct by default while C# correct by explicit coding.



I may mutter about some details from time to time, but the truth is I
like C++/CLI very much.






Best regards,

Ioannis Vranos
 
I

Ioannis Vranos

Ioannis Vranos wrote:

I am sorry to disappoint you but you are wrong. Check these:


http://microsoft.sitestream.com/TechEd/DEV/DEV333_files/Botto_files/DEV333_Sutte.ppt



http://www.accu.org/conference/pres...Relevant_on_Modern_Environments_(keynote).pdf




Read that C++/CLI is usually 25% faster than C# for pure .NET code and
that C++/CLI is correct by default while C# correct by explicit coding.



I may mutter about some details from time to time, but the truth is I
like C++/CLI very much.


And to make the above more clear, C++/CLI will be more powerful than C#.
Except of the low level IL stuff and the language stuff like templates
used with managed types and generics used in combination with templates
that will not be able with C#, there are heavy optimisations from the
compiler including the upcoming POGO optimisation available only for C++
..NET programs.






Best regards,

Ioannis Vranos
 
G

Guest

Have you tried being more explicit in your declaration and see if that
works?

e.x.: System::String str = S"Hello World";

Not that what you have already shouldn't work.
 
G

Gabest

I'll leave MS to answer this fully, but having done quite a bit of work
with
the existing MC++ myself, I can say that C++/CLI is a step in the right
direction. The syntax is far more natural and far more powerful. C# might
be
nice, but when it comes to raw power, it doesn't even come close to what
C++/CLI will offer, since it allows you access to almost all the features
that can be represented in metadata.

I'm sure it goes to the right direction, just wondered why it wasn't C#
going to that direction instead.
Also, it allows both templates and generics (even templates over ref
classes), which goes far beyond just the generics support in C#.

Yea, having templates is a big plus over C. For example not being able to
have type safe collection classes was my biggest complain about C# (also
true for delphi and java).
If you haven't already, I'd strongly suggest reading both the C++/CLI
migration guide I referenced in an earlier message, as well as all the
blog
entries by Brandon Bray !(http://blogs.msdn.com/branbray) and Herb Sutter
(http://blogs.msdn.com/hsutter/).... they do a great job of explaining the
rationale for the new syntax...

Thanks, I will. Though I don't have too much time to closely follow
everything but I'm very interested and always try read every topic about it
in this newsgroup.
 
G

Gabest

After having read several posts involving Ioannis Vranos' experiments

"Handle to pointer conversion"
"VC++ 2005 and ref objects in the stack"
... and this one :)
 
W

William DePalo [MVP VC++]

Ioannis Vranos said:

Yup. Seen 'em, read 'em.

As I see it the problem with C++ is that it sets the bar to entry way above
the skillsets of those who call themselves "developers" these days, some of
whom should be selling shoes. <BSEG>

C# IS THE mainstream .Net language.

C++/CLI WILL BE the .Net language used by the cognoscienti. We will continue
to be the minority.

Regards,
Will
 

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