From: agate!spool.mu.edu!caen!uakari.primate.wisc.edu!aplcen!ddsdx2.jhuapl.edu! dlc@ucbvax.Berkeley.EDU (Dave Collard)
Subject: Re: Untyped "constant"?
Date: 23 Sep 91 17:32:19 GMT [thread overview]
Message-ID: <1991Sep23.173219.15440@aplcen.apl.jhu.edu> (raw)
In <1991Sep23.164446.13412@aplcen.apl.jhu.edu> gralia@ddsdx2.jhuapl.edu (Mars J
. Gralia) writes:
>I have a question about Ada. It has to do with "named numbers" and
>their subsequent use.
>a) Suppose I have a compiler/RTE in which integer'last is 32_767.
>b) And suppose the system has a long_integer type in which
> long_integer'last = 2_147_483_647.
>c) And suppose I have the program:
> procedure Named1 is
> X : constant := integer'last+5;
> begin
> for j in 1..X loop
> null;
> end loop;
> end Named1;
>d) Finally, suppose the "loop" variables are really used. E.g., by
> disabling optimization when I invoke the compiler.
>Then: is this a legal program or not?
Nope. The declaration
X : constant := integer'last+5;
is illegal. The expression given for the initialization of a number
declaration must always be an expression of universal type. The attribute
integer'last returns an integer, not a universal_integer. Therefore, the
result of the addition will resolve to integer. Universal types must be made
up entirely of expressions involving only other universal types (literals and
other named numbers).
--Thor
>DISCUSSION
>Some compilers, admittedly archaic or for very small computers,
>will raise a Constraint_Error, thereby forcing me to say:
> X : constant long_integer := integer'last+5;
This, being a constant declaration and not a number declaration should
be fine if you convert the result of 'last to long_integer:
X : constant long_integer := long_integer(integer'last) + 5.
>I would prefer the program given above, because it would appear to be
>more portable.
>
--Thor
collard@capsrv.jhuapl.edu
next reply other threads:[~1991-09-23 17:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-09-23 17:32 agate!spool.mu.edu!caen!uakari.primate.wisc.edu!aplcen!ddsdx2.jhuapl.edu! [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-09-27 14:13 Untyped "constant"? cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!bu.edu!inmet!stt
1991-09-24 21:22 Norman H . Cohen
1991-09-24 15:08 John Goodenough
1991-09-23 16:44 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplc
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox