* Apostrophe question
@ 2007-05-01 20:36 David Smith
2007-05-02 2:48 ` Matthew Heaney
2007-05-02 10:24 ` Dmitry A. Kazakov
0 siblings, 2 replies; 3+ messages in thread
From: David Smith @ 2007-05-01 20:36 UTC (permalink / raw)
I've read a number of Ada tutorials now, and I'm unclear on when the
apostrophe is required in certain spots. For example, why is it used
here:
Father : Person_Access := new Person'(Father_First_Name,
Father_Last_Name);
but not here:
type Float_Array is array(Integer range <>) of Float;
type Float_Array_Access is access Float_Array;
V : Float_Array_Access := new Float_Array(1 .. 3);
I'm sure there is a page about this somewhere, but I can't find it.
If someone could point me in the right direction, I'd appreciate it.
-Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Apostrophe question
2007-05-01 20:36 Apostrophe question David Smith
@ 2007-05-02 2:48 ` Matthew Heaney
2007-05-02 10:24 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 2007-05-02 2:48 UTC (permalink / raw)
David Smith <david.smith@gmail.com> writes:
> Father : Person_Access := new Person'(Father_First_Name,
> Father_Last_Name);
You're comparing apples and oranges. You could have said:
Father : Person_Access := new Person; -- not initialized
and then it would be analogous to what you have below. The difference is
whether the object you're constructing is explicitly initialized.
> but not here:
>
> type Float_Array is array(Integer range <>) of Float;
> type Float_Array_Access is access Float_Array;
> V : Float_Array_Access := new Float_Array(1 .. 3);
But you could have said:
V : Float_Array_Access := new Float_Array'(1 .. 3 => 42.0);
and it would be analogous to what you have above.
> I'm sure there is a page about this somewhere, but I can't find it.
> If someone could point me in the right direction, I'd appreciate it.
The difference is whether you specify a value for the object explicitly.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Apostrophe question
2007-05-01 20:36 Apostrophe question David Smith
2007-05-02 2:48 ` Matthew Heaney
@ 2007-05-02 10:24 ` Dmitry A. Kazakov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2007-05-02 10:24 UTC (permalink / raw)
On 1 May 2007 13:36:55 -0700, David Smith wrote:
> I've read a number of Ada tutorials now, and I'm unclear on when the
> apostrophe is required in certain spots. For example, why is it used
> here:
>
> Father : Person_Access := new Person'(Father_First_Name,
> Father_Last_Name);
>
> but not here:
>
> type Float_Array is array(Integer range <>) of Float;
> type Float_Array_Access is access Float_Array;
> V : Float_Array_Access := new Float_Array(1 .. 3);
>
> I'm sure there is a page about this somewhere, but I can't find it.
> If someone could point me in the right direction, I'd appreciate it.
You mean T(...) vs T'(...), where T is the name of a [sub]type?
The former is either
1.a. Explicit type conversion
Float (1 + 2)
1.b. [Sub]type specification
Float_Array (1..3)
here Float_Array (1..3) specifies a subtype of Float_Array constrained to
the range 1..3. In the brackets you specify the constraint[s].
The latter is
2. Qualified expression. T specifies the expected [sub]type of what is in
the brackets:
Float'(1.0 + 2.0)
You need it only if the compiler could not come out without your help. Or
else when the language explicitly requires qualified expressions.
In your case, the allocator new when allocates an initialized object
requires the expression of be qualified (RM 4.8). I.e.
new 1.0 -- illegal
new Float'(1.0) -- That's OK
This is why you have to say Person' before the aggregate of Person:
(Father_First_Name, Father_Last_Name);
[ Don't ask me why new does not eat plain expressions... (:-)) ]
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-05-02 10:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-01 20:36 Apostrophe question David Smith
2007-05-02 2:48 ` Matthew Heaney
2007-05-02 10:24 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox