comp.lang.ada
 help / color / mirror / Atom feed
From: cosc19z5@Bayou.UH.EDU (Spasmo)
Subject: Re: Array Literals?
Date: 1996/08/13
Date: 1996-08-13T00:00:00+00:00	[thread overview]
Message-ID: <4uquru$jrq@Masala.CC.UH.EDU> (raw)
In-Reply-To: 4uq1jb$gpu@newsbf02.news.aol.com


John Herro (johnherro@aol.com) wrote:
: cosc19z5@Bayou.UH.EDU (Spasmo) asks if the
: following will work with any standard Ada compiler:
: > type Int_Array is array(Integer range <>) of Integer;
: > procedure Print_Int_Array ( I_List : Int_Array );
: > Print_Int_Array ( (1, 2, 3, 4) );
:      Surely!  That's standard Ada.  But there's one caution.  In your
: simple example, there's only one procedure called Print_Int_Array, and
: thus, when the compiler sees the call, it knows that the aggregate
: (1,2,3,4) must be of type Int_Array, and there's no problem.  If you had
: had several overloaded procedures with that name, each taking a different
: type, and if the aggregate (1,2,3,4) would fit more than one of those
: types, then your call would be ambiguous and wouldn't compile.  In that
: case, you would have to *qualify* the aggregate, thus:
: Print_Int_Array(Int_Array'(1,2,3,4));

Makes plenty of sense.  


:      Note the ' with the ( ).  Sometimes, for clarity, it's a good idea to
: qualify the aggregate anyway, so the reader will know what type (1,2,3,4)
: is.

Yep.  Question though, what exactly is the difference between using
Int_Array' ( ), and Int_Array ( )?  I have used the latter before
to perform conversion with no apparent ill effect, but I believe
there is a difference, I just can't seem to recall it.


:      Without realizing it, you've been using "array literals for functions
: and the like" whenever you've written a quoted string in a subprogram
: call!  For example, Put_Line("Hello"); is an abbreviation for
: Put_Line(('H','e','l','l','o'));.

Well yes I knew that string literals were a form of array literal,
but some languages have special considerations for strings so
that you could treat strings in certain ways that you may not
be able to treat standard arrays.  I just wasn't sure if Ada was
in fact this consistent in its treatment (I'm glad to see it
is).

Thanks.


: - John Herro
: Software Innovations Technology
: http://members.aol.com/AdaTutor
: ftp://members.aol.com/AdaTutor
: A: "PS/2 Microchannel, GPIB, and Greyhound."
: Q: "Name two dogs and a bus."

--
Spasmo
"Everyone has secrets, but sometimes you get caught,
 So if it's just between us, my silence can be bought"
	"Blackmail" by Sloppy Seconds





  reply	other threads:[~1996-08-13  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-12  0:00 Array Literals? Spasmo
1996-08-13  0:00 ` John Herro
1996-08-13  0:00   ` Spasmo [this message]
1996-08-14  0:00     ` John Herro
1996-08-14  0:00   ` Robert I. Eachus
1996-08-13  0:00 ` Jon S Anthony
replies disabled

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