From: jbg@sei.cmu.edu (John Goodenough)
Subject: Re: Untyped "constant"?
Date: 24 Sep 91 15:08:38 GMT [thread overview]
Message-ID: <32090@as0c.sei.cmu.edu> (raw)
In article Untyped "constant"? of 23 Sep 91 16:44:46 GMT
gralia@ddsdx2.jhuapl.edu (Mars J. Gralia) writes:
>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;
>Then: is this a legal program or not?
The named number declaration is illegal, because INTEGER'LAST is of type
INTEGER (see 3.5(9)) and the initialization expression for a named number must
have a universal type (see 3.2.2(1)). So suppose you fix this problem by
writing:
X : constant := INTEGER'POS(INTEGER'LAST) + 5;
Note that INTEGER'POS returns a value of type universal integer (see 3.5.5(6)),
INTEGER'LAST is a static expression (4.9(8)), and INTEGER'POS(INTEGER'LAST) is
static (4.9(8)).
But this doesn't solve the problem, since
for J in 1..X loop
is now equivalent to
for J in 1..32_767+5 loop
The upper and lower bounds of this range will be converted to the predefined
INTEGER type (3.6.1(2)), and this conversion will raise CONSTRAINT_ERROR.
John B. Goodenough Goodenough@sei.cmu.edu
Software Engineering Institute 412-268-6391
next reply other threads:[~1991-09-24 15:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-09-24 15:08 John Goodenough [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-23 17:32 agate!spool.mu.edu!caen!uakari.primate.wisc.edu!aplcen!ddsdx2.jhuapl.edu!
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