.NETGURU
C++/CLI experiments
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vc.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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
Reply to this message...
 
    
Hasani \(remove nospam from address\)
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.

"Ioannis Vranos" <Click here to reveal e-mail address> wrote in message
news:OUvT5%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Ioannis Vranos
Hasani (remove nospam from address) wrote:

[Original message clipped]

No, you are wrong. But I will give you the compiler messages to understand:

int main()
{
using namespace System;

String s=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
temp.cpp(5) : error C3921: Use of S-prefixed strings requires
/clr:oldSyntax command line option

When compiling with /clr, an implicit conversion exists from string
literal type to System::String^. If necessary to avoid ambiguity, cast
to System::String^

C:\c>

Best regards,

Ioannis Vranos
Reply to this message...
 
    
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.

Reply to this message...
 
    
Ioannis Vranos
Gabest wrote:

[Original message clipped]

Where?

[Original message clipped]

No.

[Original message clipped]

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

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Gabest
[Original message clipped]

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

Reply to this message...
 
    
Ioannis Vranos
Gabest wrote:

[Original message clipped]

Those were my questions/doubts about specific features of C++/CLI. Check
this:

http://www23.brinkster.com/noicys/cppcli.htm

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Tomas Restrepo \(MVP\) (VIP)
Gabest,

[Original message clipped]

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...

--
Tomas Restrepo
Click here to reveal e-mail address

Reply to this message...
 
    
Gabest
[Original message clipped]

I'm sure it goes to the right direction, just wondered why it wasn't C#
going to that direction instead.

[Original message clipped]

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).

[Original message clipped]

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.

[Original message clipped]

Reply to this message...
 
    
William DePalo [MVP VC++] (VIP)
"Gabest" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

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

Reply to this message...
 
    
Gabest
[Original message clipped]

.... and how long can it live, next to the almighty managed c++? :)

Reply to this message...
 
    
Ioannis Vranos
William DePalo [MVP VC++] wrote:

[Original message clipped]

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/presentations/Sutter_-_Is_C++_Relevant_on_Modern_Environments_%28keynote%29.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
Reply to this message...
 
    
Ioannis Vranos
Ioannis Vranos wrote:

[Original message clipped]

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
Reply to this message...
 
    
William DePalo [MVP VC++] (VIP)
"Ioannis Vranos" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I am sorry to disappoint you but you are wrong.

:-)

[Original message clipped]

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

Reply to this message...
 
    
Ioannis Vranos
William DePalo [MVP VC++] wrote:

[Original message clipped]

Yes, C# will continue to be a minority, but don't get disappointed. I
think that some of the C++/CLI stuff will eventually make into C#, while
the most important thing, to create simple hello world applications in
..NET, will continue to be feasible with C#.

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Don Kim
[Original message clipped]

I think you are correct abou this, but I got to at least hand it to
Microsoft for realizing that C++ programers were important, and putting in
all the resources to get a much better C++ to CLI binding. Though initially
I thought they were going to try and push everyone to C#, like Sun tired
(and rather arrogantly so) to get everyone to go java.

Anyway, C++ was never the language for the masses, but Visual Basic was too
light as well. C# does occupy a good middle ground, though I would prefer a
language like Python for these kinds of tasks.

Still, I hope there are a lot of opportunities with C++/CLI because I happen
to really like it.

- Don Kim

Reply to this message...
 
    
William DePalo [MVP VC++] (VIP)
"Don Kim" <Click here to reveal e-mail address> wrote in message
news:jO7Zc.13896$Click here to reveal e-mail address...
[Original message clipped]

Ditto to both sentiments. :-)

Regards,
Will

Reply to this message...
 
    
Ioannis Vranos
Don Kim wrote:
[Original message clipped]

I do not know if you know it, but C++ has been more widespread than VB,
Java and C# all these years.

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Don Kim
[Original message clipped]

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

Reply to this message...
 
    
Ioannis Vranos
Don Kim wrote:

[Original message clipped]

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

http://www.microsoft.com/downloads/details.aspx?familyid=afd04ff1-9d16-439a-9a5e-e13eb0341923&displaylang=en

[Original message clipped]

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

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Don Kim
[Original message clipped]

Yes, after installing the above, I got the exact same result as you.
Thanks.

- Don Kim

Reply to this message...
 
    
Tomas Restrepo \(MVP\) (VIP)
Ioannis,

[Original message clipped]

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....
--
Tomas Restrepo
Click here to reveal e-mail address

Reply to this message...
 
    
Ioannis Vranos
Tomas Restrepo (MVP) wrote:

[Original message clipped]

Feel free to report it yourself. :-)

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Ioannis Vranos
Ioannis Vranos wrote:

> Feel free to report it yourself. :-)

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

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Ioannis Vranos
Ioannis Vranos wrote:

> 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
Reply to this message...
 
    
Ioannis Vranos
Ioannis Vranos wrote:

[Original message clipped]

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

Best regards,

Ioannis Vranos
Reply to this message...
 
    
Ioannis Vranos
Tomas Restrepo (MVP) wrote:

[Original message clipped]

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

Best regards,

Ioannis Vranos
Reply to this message...
 
 
System.String




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification