comp.lang.ada
 help / color / mirror / Atom feed
* Need help with DEC Ada
@ 1995-01-17 21:01 Phil Dennis
  1995-01-18 18:23 ` Mats Weber
  1995-01-19 19:38 ` Robert I. Eachus
  0 siblings, 2 replies; 5+ messages in thread
From: Phil Dennis @ 1995-01-17 21:01 UTC (permalink / raw)


I'm sure that I just missed some chunk of documentation, but......

I'm running DEC Ada version 3.2 on a DEC Alpha on the OSF/1 operating
system.  I'm trying to figure out why I'm getting a warning on
a CONSTRAINT_ERROR on the array declaration, and subsequent access
type declaration.  I've included the compiler output below.

While I'm at it, I also had to change line 5 of the source code
so that the upper bound of the range was integer_32'last, rather
than (2**31) - 1.  That is because the latter expression also
generated a warning about a CONSTRAINT_ERROR.

I have compiled the same code on an IBM RISC/6000 using OC Systems
Legacy Ada, as well as their new PowerAda with no problem (save the
warning about pragma COMPONENT_ALIGNMENT).

silly                           Source Listing
          17-Jan-1995 15:51:51    DEC Ada V3.2-5-276S
                Page   1
01
          17-Jan-1995 15:51:42    silly.ada

      1 package silly is
      2
      3 pragma component_alignment(storage_unit);
      4 type integer_32 is range -(2**31) .. (2**31) -
 1;
      5 subtype natural_32 is integer_32 range 0 .. in
teger_32'last; --(2**31)-1;
      6 subtype bit is boolean;
      7 type raw_memory_t is array(natural_32) of bit;
.......1
Info: (1) CONSTRAINT_ERROR will be raised here [LRM 11
1(5)]

      8 pragma pack(raw_memory_t);
      9 type raw_memory_ptr_t is access raw_memory_t;
.......1
Info: (1) CONSTRAINT_ERROR will be raised here [LRM 11
1(5)]

     10 end silly;

Info: Package specification silly added to library /bu
2_libs/common/@coml1
    Replaces older version compiled Tue Jan 17 15:51:4
4 1995


PORTABILITY SUMMARY

pragma COMPONENT_ALIGNMENT*        3
pragma PACK                        8

	where * indicates an implementation-defined feature
\f
silly                           Source Listing
          17-Jan-1995 15:51:51    DEC Ada V3.2-5-276S
                Page   2
01
          17-Jan-1995 15:51:42    silly.ada

VERSION

  DEC Ada V3.2-5 without the Professional Development
Option


OPTIONS IN EFFECT
        -A'$ADALIB'
        -C1
        -e30
        -g1
        -i1
        -O4
        -Q0
        -V'./silly.l'


ENVIRONMENT VARIABLES IN EFFECT
        ADALIB="@/bu2_libs/common/@coml1"

        ADAERRFLAGS="isw  "   (assumed by default)
        ADALISFLAGS="ipsvw"   (assumed by default)

\f
silly                           Source Listing
          17-Jan-1995 15:51:51    DEC Ada V3.2-5-276S
                Page   3
01
          17-Jan-1995 15:51:42    silly.ada

COMPILER INTERNAL TIMING

        Phase                          CPU    Elapsed
   Page      I/O
                                     seconds  seconds
  faults    count
  Initialization                        0.05     0.06
       0        0
  Parser                                0.02     0.01
       0        0
  Static Semantics                      0.00     0.01
       0        0
  Generic Expansion                     0.00     0.00
       0        0
  Ada Back End                          0.00     0.01
       0        0
  Code Generation-Ada                   0.00     0.00
       0        0
  Smart Recompilation                   0.00     0.00
       0        0
  List Generation                       0.00     0.00
       0        0
  Compilation Library                   0.03     0.01
       0        0
  Writing Units to Library              0.02     0.04
       0        0
  Analysis Data Collection              0.00     0.00
       0        0
  Compiler totals                       0.18     0.23
       0        0




COMPILATION STATISTICS

  CPU time:          0.18 seconds
  Elapsed time:      0.23 seconds
  Pagefaults:           0
  I/O Count:            0
  Source lines:        10

  3333 lines per CPU minute.
  Compilation complete

*************************************************************
*Thanks to the Interstate Highway System, it is now possible*
*to travel across the country from coast to coast without   *
*seeing anything.       --Charles Kuralt                    *
*                                                           *
*ALL STANDARD DISCLAIMERS APPLY,           Next time,       *
*PDENNIS@VNET.IBM.COM A.K.A. PHIL DENNIS   take the train!  *
*************************************************************



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help with DEC Ada
  1995-01-17 21:01 Need help with DEC Ada Phil Dennis
@ 1995-01-18 18:23 ` Mats Weber
  1995-01-20  5:22   ` Robert Dewar
  1995-01-19 19:38 ` Robert I. Eachus
  1 sibling, 1 reply; 5+ messages in thread
From: Mats Weber @ 1995-01-18 18:23 UTC (permalink / raw)


In article <19950117.160119.606@vnet.ibm.com>, pdennis@vnet.ibm.com (Phil
Dennis) wrote:

>       3 pragma component_alignment(storage_unit);
>       4 type integer_32 is range -(2**31) .. (2**31) -
>  1;
>       5 subtype natural_32 is integer_32 range 0 .. in
> teger_32'last; --(2**31)-1;

the original (2**31)-1 should not cause any problem. Ae you really sure it
generates a warning ?

>       6 subtype bit is boolean;
>       7 type raw_memory_t is array(natural_32) of bit;
> .......1
> Info: (1) CONSTRAINT_ERROR will be raised here [LRM 11
> 1(5)]

While elaborating a type declaration, all sorts of attributes of the type
are calculated, such as its 'Size and 'Length attributes. Here the
compiler can see that the 'Length attribute of raw_memory_t will be 2^31,
which is too big an integer to be represented by any integer variable with
your compiler.

BTW, what were you thinking of doing with that type ? I can only see
erroneous uses of it :-)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help with DEC Ada
  1995-01-17 21:01 Need help with DEC Ada Phil Dennis
  1995-01-18 18:23 ` Mats Weber
@ 1995-01-19 19:38 ` Robert I. Eachus
  1 sibling, 0 replies; 5+ messages in thread
From: Robert I. Eachus @ 1995-01-19 19:38 UTC (permalink / raw)



In article <19950117.160119.606@vnet.ibm.com> pdennis@vnet.ibm.com (Phil Dennis) writes:

  > While I'm at it, I also had to change line 5 of the source code
  > so that the upper bound of the range was integer_32'last, rather
  > than (2**31) - 1.  That is because the latter expression also
  > generated a warning about a CONSTRAINT_ERROR.

    Your new form is correct and protable.  The old version runs into
a particularly nasty effect of the Ada type model.  (The expression
works for the type declaration, because those bounds can be of any
integer type.  But here the bounds must be of the parent type,
therefore the expression is evaluated using integer_32 arithmetic.)

 >	 7 type raw_memory_t is array(natural_32) of bit;
 >  .......1
 >  Info: (1) CONSTRAINT_ERROR will be raised here [LRM 11
 >  1(5)]

    I count this as a bug, but I remember someone from DEC arguing
otherwise.  Storage_Error here would not be surprising, but I think
what DEC is doing is evaluating the bounds of an unpacked array.  When
they reach the pramga pack, it is too late to go back.  (On the other
hand, you might want to try a range 0..integer_32'last. That might
make the size calculation more successful.  The current range includes
an odd number of bits.)

 >	 8 pragma pack(raw_memory_t);
 >	 9 type raw_memory_ptr_t is access raw_memory_t;
 >  .......1
 >  Info: (1) CONSTRAINT_ERROR will be raised here [LRM 11
 >  1(5)]

    This is totally bogus!  It is perfectly legitimate to have an
access type where the collection can never be populated, and no object
of the type is ever created.  The access type need not point to a bit,
in this case it designates an array type, so there should be no magic
packing of pointers involved.

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help with DEC Ada
  1995-01-18 18:23 ` Mats Weber
@ 1995-01-20  5:22   ` Robert Dewar
  1995-01-23 16:22     ` Mats Weber
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Dewar @ 1995-01-20  5:22 UTC (permalink / raw)


Mats says:

"the original (2**31)-1 should not cause any problem. Ae you really sure it
generates a warning ?"

sorry Mats, that is wrong, in Ada 83, this expression was not a static
expression evaluated at compile time, and hence a compiler is allowed to
compute it at runtime, insisting that all intermediate values are in 
range of the type (in this case a 32 bit integer).

So Dec Ada is perfectly correct (just not very friendly) in raising CE
in this situation.

Whatever model you have that says that this should not cause any problem
is flawed with respect to Ada 83. However, as I pointed out in a previous
message, Ada 95 has "fixed" this "problem" by requiring static expressions
to be evaluated exactly, even when they appear as subexpressions of non
static exprssions, or in contexts not requiring static expressions.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Need help with DEC Ada
  1995-01-20  5:22   ` Robert Dewar
@ 1995-01-23 16:22     ` Mats Weber
  0 siblings, 0 replies; 5+ messages in thread
From: Mats Weber @ 1995-01-23 16:22 UTC (permalink / raw)


In article <3fnhbe$4lq@gnat.cs.nyu.edu>, dewar@cs.nyu.edu (Robert Dewar) wrote:

> Mats says:
> 
> "the original (2**31)-1 should not cause any problem. Ae you really sure it
> generates a warning ?"
> 
> sorry Mats, that is wrong, in Ada 83, this expression was not a static
> expression evaluated at compile time, and hence a compiler is allowed to
> compute it at runtime, insisting that all intermediate values are in 
> range of the type (in this case a 32 bit integer).

Right. But there is a workaround in Ada 83, using a named number:

   Upper : constant := (2**31)-1;
   type T is range 0 .. Upper;

which forces the computation to be done in universal-integer.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1995-01-23 16:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-01-17 21:01 Need help with DEC Ada Phil Dennis
1995-01-18 18:23 ` Mats Weber
1995-01-20  5:22   ` Robert Dewar
1995-01-23 16:22     ` Mats Weber
1995-01-19 19:38 ` Robert I. Eachus

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