Re: System::String question
From: Kapil Khosla [MSFT] (kkhosla_at_online.microsoft.com)
Date: 02/03/05
- Next message: Sandy: "sending data to opened notepad file in desktop"
- Previous message: Kapil Khosla [MSFT]: "Re: Compiler error - incorrect error message "illegal type for non-type template parameter""
- In reply to: Ioannis Vranos: "Re: System::String question"
- Next in thread: Kapil Khosla [MSFT]: "Re: System::String question"
- Reply: Kapil Khosla [MSFT]: "Re: System::String question"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 2 Feb 2005 21:51:25 -0800
I know it looks odd, but you code would work in the following manner
int main()
{
using namespace System;
String ^ms("Test string"); // note the hat.
char c;
for(long i=0; i<ms->Length; ++i)
c=ms[i];
}
I will follow up up on why decided to disallow String with stack semantics
and allow ref class with stack semantics.
Thanks,
Kapil
"Ioannis Vranos" <ivr@remove.this.grad.com> wrote in message
news:ecajh%23$BFHA.520@TK2MSFTNGP09.phx.gbl...
> Tamas Demjen wrote:
>
>> That's odd. If I create my own ref class and instantiate it with the
>> stack syntax, it works. It's hard to understand why it wouldn't work with
>> strings. After all, the stack instantiation of ref classes is just a
>> syntactical trick, in the reality the object is not created on the stack
>> but on the managed heap. It just makes the programmer's job easier, and
>> the application safer. When we write
>>
>> String ms= "Test string";
>> ms.[...]
>>
>> I expect that the compiler generates this code (or at least functionally
>> equivalent):
>> String^ ms = gcnew String("Test string");
>> try
>> {
>> ms->[...]
>> }
>> finally
>> {
>> delete ms;
>> }
>>
>> It sounds very odd to me that the stack syntax works with every ref
>> class, except String. I see no reason behind it. But I didn't bother
>> reading the entire standard proposal, so they should know better.
>>
>> I've created a ScopedPtr ref class that's similar to boost::scoped_ptr.
>> It's a ref class that safeguards an unmanaged pointer, and so far it
>> worked with the stack syntax.
>
>
> I just edited the bug report:
>
>
> "Edited by Ioannis Vranos on 2005-01-31 at 17:42:13
> Actually the reported bug was intended to be for stack semantics, and
> since C++/CLI does not include implicit type conversions with
> constructors, the code should have been:
>
> int main()
> {
> using namespace System;
>
> String ms("Test string");
>
> char c;
>
> for(long i=0; i<ms.Length; ++i)
> c=ms[i];
> }
>
> I changed the posted code to this one, in the "Steps to Reproduce" below.
>
> ==> Still the crash remains the same."
>
>
>
> My bug report was changed to
>
> Status: Resolved
> Resolution: By Design
>
>
> after that obscure answer, and because of that I guess the bug will
> remain...
>
>
>
>
> --
> Ioannis Vranos
- Next message: Sandy: "sending data to opened notepad file in desktop"
- Previous message: Kapil Khosla [MSFT]: "Re: Compiler error - incorrect error message "illegal type for non-type template parameter""
- In reply to: Ioannis Vranos: "Re: System::String question"
- Next in thread: Kapil Khosla [MSFT]: "Re: System::String question"
- Reply: Kapil Khosla [MSFT]: "Re: System::String question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|