comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: String declaration and initialization
Date: Thu, 22 May 2008 13:11:20 -0400
Date: 2008-05-22T13:11:20-04:00	[thread overview]
Message-ID: <wcc4p8qmfgn.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: g148oh$mcd$1@registered.motzarella.org

S�bastien <seb.morand@gmail.com> writes:

> But you give me an Idea :
> declare
>     buffer: access String;
>     Free_String is new Unchecked_Deallocation(String, access all String);
> begin
>     case SomeTest is
>         case TEST1 =>
>             buffer := new String("Test1");
>         case TEST2 =>
>             buffer := new String("Test2");
>     end case;
>     MyTreatment1(buffer.all, buffer.all'Size);
>     MyTreatment2(buffer.all, buffer.all'Size);
>     MyTreatment3(buffer.all, buffer.all'Size);
> end;
>
> but it doesn't work of course since I can't create with new an
> unconstrained object.

Sure you can:

    buffer := new String'("Test1");
                        ^
                        | Note tick mark!


<< new String("Test1"); >> does not make sense.  You have to use a
qualified expression (as above) or a constrained subtype,
as in:

    new String(1..10)

You didn't call Free_String, by the way.  Think about whether you want
to call it in case of exception!

- Bob



  reply	other threads:[~2008-05-22 17:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 15:47 String declaration and initialization Sébastien
2008-05-22 16:05 ` Dmitry A. Kazakov
2008-05-22 16:47   ` Sébastien
2008-05-23  8:18     ` Dmitry A. Kazakov
2008-05-23  9:33       ` Sébastien
2008-05-22 16:16 ` Matthew Heaney
2008-05-22 16:58   ` Sébastien
2008-05-22 17:11     ` Robert A Duff [this message]
2008-05-22 18:16     ` Matthew Heaney
2008-05-22 20:01     ` Jeffrey R. Carter
2008-05-22 16:40 ` Jean-Pierre Rosen
2008-05-22 18:09 ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox