comp.lang.ada
 help / color / mirror / Atom feed
From: "Hibou57 (Yannick Duchêne)" <yannick_duchene@yahoo.fr>
Subject: Re: Hiding the value of Constants
Date: Tue, 7 Jul 2009 03:41:21 -0700 (PDT)
Date: 2009-07-07T03:41:21-07:00	[thread overview]
Message-ID: <5b49f256-f779-4030-a50d-5f31fd08ddff@26g2000yqk.googlegroups.com> (raw)
In-Reply-To: 4a531837$0$30227$9b4e6d93@newsspool1.arcor-online.net

On 7 juil, 11:41, Georg Bauhaus <rm.dash-bauh...@futureapps.de> 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)



  reply	other threads:[~2009-07-07 10:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-07  8:48 Hiding the value of Constants Rick
2009-07-07  8:54 ` xavier grave
2009-07-07  8:58   ` AdaMagica
2009-07-07  9:41 ` Georg Bauhaus
2009-07-07 10:41   ` Hibou57 (Yannick Duchêne) [this message]
2009-07-07 15:51     ` Adam Beneschan
2009-07-07 16:26       ` Hibou57 (Yannick Duchêne)
2009-07-07 18:48       ` Dmitry A. Kazakov
2009-07-07 19:05         ` Adam Beneschan
2009-07-07 19:53           ` Dmitry A. Kazakov
2009-07-07 20:28             ` Adam Beneschan
2009-07-07 20:57               ` Dmitry A. Kazakov
2009-07-08 10:25                 ` Georg Bauhaus
2009-07-08 12:20                   ` Dmitry A. Kazakov
2009-07-09 23:04 ` anon
2009-07-10  6:37   ` AdaMagica
2009-07-11 19:06     ` anon
2009-07-11 19:26       ` Georg Bauhaus
2009-07-11 21:53         ` anon
2009-07-11 22:03           ` Albrecht Käfer
2009-07-11 22:15           ` Ed Falis
2009-07-15  9:30             ` anon
2009-07-11 23:31           ` Egil
replies disabled

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