Re: Hiding the value of Constants
- From: Hibou57 (Yannick Duchêne) <yannick_duchene@xxxxxxxx>
- Date: Tue, 7 Jul 2009 03:41:21 -0700 (PDT)
On 7 juil, 11:41, Georg Bauhaus <rm.dash-bauh...@xxxxxxxxxxxxx> wrote:
I'm assuming you do not want the value to be
visible neither in the private part nor in the
public part of the package specification?
Use a function then, and make the package pure,
if possible:
package P is
pragma pure;
type Thing is ...;
function My_Constant return Thing;
pragma Inline(My_constant);
end P;
Chances are that the compiler might be able to
act as if My_Constant was a simple constant.
As some one are talking about Funny_Types, here is a funny thing
(thinking about it when I saw this solution) : Ada defines enumeration
contants as parameterless functions (just like you propose for these
constants).
RM 2005 3.5.1 says:
6 {enumeration literal} Each enumeration_literal_specification is the
explicit declaration of the corresponding enumeration literal: it
declares a parameterless function, whose defining name is the
defining_identifier or defining_character_literal, and whose result
type is the enumeration type.
But this is with some restrictions (ex. one may not get the adress of
such a function)
This has some conscequences on the name resolution of an enumeration
literal reference vs of a constant reference. Sometimes I wish both
will be one day handled the same (enumeration literals and constants)
.
- Follow-Ups:
- Re: Hiding the value of Constants
- From: Adam Beneschan
- Re: Hiding the value of Constants
- References:
- Hiding the value of Constants
- From: Rick
- Re: Hiding the value of Constants
- From: Georg Bauhaus
- Hiding the value of Constants
- Prev by Date: Re: Lego Mindstoms for Ada: user group
- Next by Date: Re: Lego Mindstoms for Ada: user group
- Previous by thread: Re: Hiding the value of Constants
- Next by thread: Re: Hiding the value of Constants
- Index(es):
Relevant Pages
|