Re: System::String question

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Kapil Khosla [MSFT] (kkhosla_at_online.microsoft.com)
Date: 02/03/05


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



Relevant Pages

  • File IO
    ... filing a bug report or something. ... THe problem is with using implicit do loops to read: ... it blows stack. ... So I set my stacksize limit to unlimited and re-rerun. ...
    (comp.lang.fortran)
  • Re: Set Up To Print Book, 2 Sides, L & R Margins Alternate-Pagination
    ... chapter a new section which starts on odd page. ... Printing might be more interesting. ... Place the output stack back in the input hopper ... The result is a duplex stack in the ...
    (microsoft.public.mac.office.word)
  • Re: Manual duplex printing requires each finished page to be flipp
    ... Daiya ... > SIDE B. This means that if you thumbed through the output stack, ... > If I do this all semi-manually (printing just the odd pages and then just ...
    (microsoft.public.word.docmanagement)
  • Re: Manual duplex printing requires each finished page to be flipp
    ... the first sheet in the stack will have PAGE 2 on SIDE A and ... SIDE B. This means that if you thumbed through the output stack, ... If I do this all semi-manually (printing just the odd pages and then just ... > What *is* the sequence of page images that Word is sending to the printer? ...
    (microsoft.public.word.docmanagement)
  • Re: AVR stack problem
    ... > reason it looks like my stack is disabled. ... It appears that your fuse bits are still in compatibility mode i.e. ... certain odd problems arise out of the situation that the AVR ...
    (comp.arch.embedded)