Re: Hiding the value of Constants



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)
.



Relevant Pages

  • Re: P+D Wizard reports missing files
    ... Hope I offended noone (including George Bush, ... enumeration number. ... shouldn't normally be included with a install package. ... Here you stated your opinion, ...
    (microsoft.public.vb.general.discussion)
  • Re: P+D Wizard reports missing files
    ... enumeration number. ... shouldn't normally be included with a install package. ... Here you stated your opinion, ... Depends on your Windows version. ...
    (microsoft.public.vb.general.discussion)
  • Re: Solid edge .. progress... new laptop
    ...    as it turns out so far not much faster than my 500 dollar ... I will probably slide my first synch class to Oct or Nov. ... your existing CAD package. ... quite a bit less than half the retail price for SE in year one... ...
    (comp.cad.solidworks)
  • Re: Solid edge .. progress... new laptop
    ...    as it turns out so far not much faster than my 500 dollar ... I will probably slide my first synch class to Oct or Nov. ... your existing CAD package. ... So if my CAD package qualifies, it does indeed sound like a good deal. ...
    (comp.cad.solidworks)
  • Re: P+D Wizard reports missing files
    ... Hope I offended noone (including George Bush, ... enumeration number. ... shouldn't normally be included with a install package. ... Here you stated your opinion, ...
    (microsoft.public.vb.general.discussion)