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


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));
     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.
     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'));.
- 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."




  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 [this message]
1996-08-13  0:00   ` Spasmo
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