From: Robert A Duff <bobduff@TheWorld.com>
Subject: Re: Need some help in Ada
Date: Wed, 23 Mar 2016 17:06:30 -0400
Date: 2016-03-23T17:06:30-04:00 [thread overview]
Message-ID: <wccpouklx9l.fsf@TheWorld.com> (raw)
In-Reply-To: fee2c972-db94-402c-b2ee-c80fc8dc329b@googlegroups.com
danifreecs@gmail.com writes:
> Thank you for the reply! So it should be Components: String(1..Size)?
Yes.
> then i wrote this:
> function Create(Str : String) return J_String is
> Jstr: J_String(Str'Length);
> begin
> if (Str'Length = 0) then
> Jstr.Components := "";
> else
> Jstr.Components := Str;
> end if;
> return Jstr;
> end Create;
That looks like it will work, although you should try to format it in a
more standard way. But it's more complicated than it needs to be. You
don't need to special case the empty string. A single return statement,
returning an aggregate, will work:
return (Size => ..., Components => ...);
I think you can figure out what the "..." parts should be.
> when i try to use it like: jstr1: J_String(4) := Create("doge");
> i get this error "expected private type ada.text_io.file_type" which
> i can't really understand.
That's a visibility problem. Your Create is not directly visible,
but the Create in Ada.Text_IO is, so the compiler thinks you want
the latter. You need a "use" clause, or you need to say
J_String_Pkg.Create(...).
By the way, you don't want that "4":
jstr1: J_String := Create("doge");
or maybe:
jstr1: constant J_String := Create("doge");
Let the program figure out the length. You shouldn't have to count the
number of characters in "doge".
- Bob
next prev parent reply other threads:[~2016-03-23 21:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-23 19:29 Need some help in Ada danifreecs
2016-03-23 19:51 ` Anh Vo
2016-03-23 20:24 ` danifreecs
2016-03-23 20:52 ` Anh Vo
2016-03-23 21:11 ` danifreecs
2016-03-23 21:34 ` Anh Vo
2016-03-23 21:06 ` Robert A Duff [this message]
2016-03-23 21:10 ` Niklas Holsti
2016-03-23 21:18 ` danifreecs
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox