From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Renaming of enumeration constant
Date: Sat, 12 Jun 2004 00:01:27 -0400
Date: 2004-06-12T00:01:27-04:00 [thread overview]
Message-ID: <3c2dne2BD4WFHVfd4p2dnA@comcast.com> (raw)
In-Reply-To: <ca9v8l$5gb8@cui1.lmms.lmco.com>
Xenos wrote:
> Just a curiosity question:
>
> What is the difference (advantages, etc.) of defining a function rename for
> an enumeration constant over just creating a constant. Consider:
>
> package X is
> type E is (A, B, C);
> end X;
>
> with X;
> package Y is
> function A return X.E renames X.A;
> end Y;
>
> with X;
> package Z is
> A : constant X.E := X.A;
> end Z;
>
> Is the "A" in Y treated any different than the "A" in Z by the compiler, or
> will both achieve the same results. Is one considered "better" (whatever
> that means) than the other?
The difference is that a function will overload other functions and
procedures of the same name, while a constant will hide such names in
the local scope, and prevent them from being use visible.
So if you have two packages that declare function A, and use clauses for
both packages you can call either, unless the call is ambiguous. If you
have two packages that declare constants A, and use clauses for both,
you will still have to use a qualified name to reference A.
A different advantage to using functions instead of constants is that
you can do the renaming in the body of the package:
package Foo is
function A return Bar;
...
package body Foo is
function A renames...
I'll let you read about the joys and issues of renaming as body. But if
the value may change during development, this is the form you want.
The advantage of the constant form is when you want it to be static.
For example:
Pi: constant := 3.14159_26...;
(If the value of Pi changes the need to modify your program is a minor
detail.)
--
Robert I. Eachus
The ideology he opposed throughout his political life insisted that
history was moved by impersonal tides and unalterable fates. Ronald
Reagan believed instead in the courage and triumph of free men and we
believe it all the more because we saw that courage in him. -- George
W. Bush June 11, 2004
prev parent reply other threads:[~2004-06-12 4:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-10 15:37 Renaming of enumeration constant Xenos
2004-06-10 17:38 ` Nick Roberts
2004-06-10 20:40 ` Xenos
2004-06-11 9:25 ` Jean-Pierre Rosen
2004-06-11 12:00 ` Nick Roberts
2004-06-11 12:49 ` Dmitry A. Kazakov
2004-06-12 4:34 ` Robert I. Eachus
2004-06-12 4:01 ` Robert I. Eachus [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox