comp.lang.ada
 help / color / mirror / Atom feed
* Re: Constraint or what?
  2000-02-10  0:00 Constraint or what? Jan Wuyts
@ 2000-02-10  0:00 ` reason67
  2000-02-11  0:00 ` Pascal Martin
  2000-02-16  0:00 ` Ian Ward
  2 siblings, 0 replies; 6+ messages in thread
From: reason67 @ 2000-02-10  0:00 UTC (permalink / raw)


In article <38A2A395.FD028B73@alcatel.be>,
  Jan.Wuyts@alcatel.be wrote:
> Hi guys,
>
> We're doing a port Alsys -> VADS or whatever they are called these
> days.  This maybe a stupid question but I'll take the risk.
>
> The Alsys didn't complain on the construct below but the VADS one
does.
> I know about the restrictions on UNCHECKED_CONVERSION and the VADS
> documentation says the target type cannot be an unconstraint array but
I
> assumed it was constraint.  So, why does the VADS compiler issue an
> error...

I have seen this warning message in VADS and Apex (Same company). It is
only a warning and should be disregarded. It brings it up based on the
base type which is unconstrained, not the subtype which is.
---
Jeffrey Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Constraint or what?
@ 2000-02-10  0:00 Jan Wuyts
  2000-02-10  0:00 ` reason67
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jan Wuyts @ 2000-02-10  0:00 UTC (permalink / raw)


Hi guys,

We're doing a port Alsys -> VADS or whatever they are called these
days.  This maybe a stupid question but I'll take the risk.

The Alsys didn't complain on the construct below but the VADS one does. 
I know about the restrictions on UNCHECKED_CONVERSION and the VADS
documentation says the target type cannot be an unconstraint array but I
assumed it was constraint.  So, why does the VADS compiler issue an
error...

Can anyone help me?

Here is what I do:

--------------------
...in ADT_ADU...
   MAX_BINARY_BUFFER_SIZE : constant integer
      := ADT_ADU_DESCRIPTION.MAX_BINARY_BUFFER_SIZE;
   subtype T_BINARY_BUFFER_SIZE is 
			INTEGER range 0..MAX_BINARY_BUFFER_SIZE;
   type T_BINARY_BUFFER is array (T_BINARY_BUFFER_SIZE range <>) of
             NUMERIC_TYPES.UNSIGNED_INTEGER8;

... in NUMERIC_TYPES ...
  type UNSIGNED_INTEGER8 is range 0 .. 255;
  for UNSIGNED_INTEGER8'size use 8;

  type UNSIGNED_INTEGER8_ARRAY is 
		array (POSITIVE range <>) of UNSIGNED_INTEGER8;
  pragma PACK (UNSIGNED_INTEGER8_ARRAY);

  subtype BYTE_ARRAY is  UNSIGNED_INTEGER8_ARRAY;

... in the failing procedure...
DUMP_BIN_BUF:
declare
    BUFSIZ : constant ADT_ADU.T_BINARY_BUFFER_SIZE 
              			:= ADT_ADU.BINARY_BUFFER_SIZE(ADU);
    BUF : ADT_ADU.T_BINARY_BUFFER(1..BUFSIZ);
    subtype LIMITED_BYTE_ARRAY_RANGE is 
		POSITIVE range 1..BUFSIZ +1;

    subtype LIMITED_BYTE_ARRAY is NUMERIC_TYPES.BYTE_ARRAY
					(LIMITED_BYTE_ARRAY_RANGE);
    function TO_BYTE_ARRAY is new
		UNCHECKED_CONVERSION (TARGET=> LIMITED_BYTE_ARRAY,
				SOURCE=> ADT_ADU.T_BINARY_BUFFER); 
	---- This is where the VADS compiler says...
	---- error: RM Appendix F: target type must not be 
	----            unconstrained array or record type

begin
    ADT_ADU.GET_BINARY_BUFFER(ADU, BUF);
    return "BUFFER_SIZE=>"& INTEGER'IMAGE(BUFSIZ) & ","
            & ASCII.LF & "BUFFER=>("
            & ASCII.LF & LOG.DUMP_BYTE_ARRAY( 
                                 TO_BYTE_ARRAY( BUF )
                                             )
            & ASCII.LF & ASCII.HT & ")";
exception
--------------------

In my opinion LIMITED_BYTE_ARRAY is constraint so...

Thanks for the help
-- 
                                        _____________
      Jan Wuyts (RX)                    \     ^     /
                                         \ALC/_\TEL/
------------------------------------------\       /----
 Internet: wuytsj@rsd.bel.alcatel.be       \ ,,, /     
           jan.wuyts@alcatel.be             (. .)      
-----------------------------------------o00-(_)-00o---
Alcatel Bell Space                            V
 Berkenrodelei 33         Phone:    (+32) 3/829.5479
  B-2660 Hoboken          Fax:      (+32) 3/829.5763
     Belgium.




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

* Re: Constraint or what?
  2000-02-10  0:00 Constraint or what? Jan Wuyts
  2000-02-10  0:00 ` reason67
@ 2000-02-11  0:00 ` Pascal Martin
  2000-02-13  0:00   ` Robert Dewar
  2000-02-18  0:00   ` Robert Dewar
  2000-02-16  0:00 ` Ian Ward
  2 siblings, 2 replies; 6+ messages in thread
From: Pascal Martin @ 2000-02-11  0:00 UTC (permalink / raw)


IMHO, the type is not a constraint type, because of the range <>.

The fact that the subtype T_BINARY_BUFFER_SIZE is given a
limited (?) range is pointless. From your code, we cannot even be
sure that this subtype does not have the same range as NATURAL.
Anyway, NATURAL itself is a subtype with a constraint, somewhat
equivalent to:

subtype NATURAL is range 0 .. INTEGER'LAST;

In this computer world, every integer has constraints..

What is important is that the size of type T_BINARY_BUFFER is
not statically defined (because of range <>).

Some compilers can consider this type as constrained if its size stays
small (but we cannot tell from your posting), "small" being implementation
dependent. Some other compilers, such as the Alsys ones, go the extra 
mile to deal with the size at execution time. The VADS compiler has 
the reputation to be strict and to make no specific effort whatsoever.

Another well known effect is stack overflow, because the VADS
compiler tends to reserve the maximum size if a static constraint
is not used, even for local variables.

BTW, in a somewhat related topic, I have been hit a few days ago 
by the following C code:

int i;

if (i < 0) i = 0 - i;
.. assume i >= 0 ...

On most computers, this does not work for 1 value: -2**31, 
as 0 - (-2**31) is equal to -2**31 (C int is a modulo type,
only because the machine happens to be so).
 
Sometime I really wish CONSTRAINT_ERROR exists in C !

This is to remind people that all numeric types have constraints,
and that using subtype with explicit limits change little to the
nature of the type. It merely change the actual value of the limits.

Pascal.


In article <87uojc$gav$1@nnrp1.deja.com>, reason67@my-deja.com wrote:
> In article <38A2A395.FD028B73@alcatel.be>,
>   Jan.Wuyts@alcatel.be wrote:
>> Hi guys,
>>
>> We're doing a port Alsys -> VADS or whatever they are called these
>> days.  This maybe a stupid question but I'll take the risk.
>>
>> The Alsys didn't complain on the construct below but the VADS one
> does.
>> I know about the restrictions on UNCHECKED_CONVERSION and the VADS
>> documentation says the target type cannot be an unconstraint array but
> I
>> assumed it was constraint.  So, why does the VADS compiler issue an
>> error...
> 
> I have seen this warning message in VADS and Apex (Same company). It is
> only a warning and should be disregarded. It brings it up based on the
> base type which is unconstrained, not the subtype which is.
> ---
> Jeffrey Blatt
> 
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.


-- 

------------------------------------------------------------------
Pascal F. Martin.






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

* Re: Constraint or what?
  2000-02-11  0:00 ` Pascal Martin
@ 2000-02-13  0:00   ` Robert Dewar
  2000-02-18  0:00   ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Dewar @ 2000-02-13  0:00 UTC (permalink / raw)


In article <o7Po4.101$m35.5175@typhoon.we.mediaone.net>,
  Pascal Martin <pascal.martin@iname.com.nospam> wrote:
> Another well known effect is stack overflow, because the VADS
> compiler tends to reserve the maximum size if a static
> constraint is not used, even for local variables.

This is not a valid implementation for arrays. There was an
explicit ACVC challenege from a compiler that did this and
blew up on one of the tests, and the protest was rejected.
Compilers should not allocate maximum space for variable
length arrays.

Now it is reasonable to do this for very small arrays for
some definition of very small, but to cause stack overflow
from this approach seems quite definitely a bug to me.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Constraint or what?
  2000-02-10  0:00 Constraint or what? Jan Wuyts
  2000-02-10  0:00 ` reason67
  2000-02-11  0:00 ` Pascal Martin
@ 2000-02-16  0:00 ` Ian Ward
  2 siblings, 0 replies; 6+ messages in thread
From: Ian Ward @ 2000-02-16  0:00 UTC (permalink / raw)


Dat denk je maar, nieuw Ariel Gaat diep in de vezels...

I have seen this before, I seem to recall that the compiler thought
that, as it was only a subtype of POSITIVE, it did not think that
it was constrained. I demonstrated this on the compiler in question,
by creating a huge range, within a Type

eg. Type x is range 0 .. 2**30-1, or whatever

Then derived the subtype constraint fron the new type,
instead of positive.

    subtype arrayrng is x range 0..30;

 It then worked. I did not investigate
this any further, once I'd got it to work.


Groetjes,
Ian.



Jan Wuyts wrote in message <38A2A395.FD028B73@alcatel.be>...
>Hi guys,
>
>We're doing a port Alsys -> VADS or whatever they are called these
>days.  This maybe a stupid question but I'll take the risk.
>
>The Alsys didn't complain on the construct below but the VADS one does.
>I know about the restrictions on UNCHECKED_CONVERSION and the VADS
>documentation says the target type cannot be an unconstraint array but I
>assumed it was constraint.  So, why does the VADS compiler issue an
>error...
>
>Can anyone help me?
>
>Here is what I do:
>
>--------------------
>...in ADT_ADU...
>   MAX_BINARY_BUFFER_SIZE : constant integer
>      := ADT_ADU_DESCRIPTION.MAX_BINARY_BUFFER_SIZE;
>   subtype T_BINARY_BUFFER_SIZE is
> INTEGER range 0..MAX_BINARY_BUFFER_SIZE;
>   type T_BINARY_BUFFER is array (T_BINARY_BUFFER_SIZE range <>) of
>             NUMERIC_TYPES.UNSIGNED_INTEGER8;
>
>... in NUMERIC_TYPES ...
>  type UNSIGNED_INTEGER8 is range 0 .. 255;
>  for UNSIGNED_INTEGER8'size use 8;
>
>  type UNSIGNED_INTEGER8_ARRAY is
> array (POSITIVE range <>) of UNSIGNED_INTEGER8;
>  pragma PACK (UNSIGNED_INTEGER8_ARRAY);
>
>  subtype BYTE_ARRAY is  UNSIGNED_INTEGER8_ARRAY;
>
>... in the failing procedure...
>DUMP_BIN_BUF:
>declare
>    BUFSIZ : constant ADT_ADU.T_BINARY_BUFFER_SIZE
>              := ADT_ADU.BINARY_BUFFER_SIZE(ADU);
>    BUF : ADT_ADU.T_BINARY_BUFFER(1..BUFSIZ);
>    subtype LIMITED_BYTE_ARRAY_RANGE is
> POSITIVE range 1..BUFSIZ +1;
>
>    subtype LIMITED_BYTE_ARRAY is NUMERIC_TYPES.BYTE_ARRAY
> (LIMITED_BYTE_ARRAY_RANGE);
>    function TO_BYTE_ARRAY is new
> UNCHECKED_CONVERSION (TARGET=> LIMITED_BYTE_ARRAY,
> SOURCE=> ADT_ADU.T_BINARY_BUFFER);
> ---- This is where the VADS compiler says...
> ---- error: RM Appendix F: target type must not be
> ----            unconstrained array or record type
>
>begin
>    ADT_ADU.GET_BINARY_BUFFER(ADU, BUF);
>    return "BUFFER_SIZE=>"& INTEGER'IMAGE(BUFSIZ) & ","
>            & ASCII.LF & "BUFFER=>("
>            & ASCII.LF &
.DUMP_BYTE_ARRAY( 
>                                 TO_BYTE_ARRAY( BUF )
>                                             )
>            & ASCII.LF & ASCII.HT & ")";
>exception
>--------------------
>
>In my opinion LIMITED_BYTE_ARRAY is constraint so...
>
>Thanks for the help
>-- 
>                                        _____________
>      Jan Wuyts (RX)                    \     ^     /
>                                         \ALC/_\TEL/
>------------------------------------------\       /----
> Internet: wuytsj@rsd.bel.alcatel.be       \ ,,, /     
>           jan.wuyts@alcatel.be             (. .)      
>-----------------------------------------o00-(_)-00o---
>Alcatel Bell Space                            V
> Berkenrodelei 33         Phone:    (+32) 3/829.5479
>  B-2660 Hoboken          Fax:      (+32) 3/829.5763
>     Belgium.







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

* Re: Constraint or what?
  2000-02-11  0:00 ` Pascal Martin
  2000-02-13  0:00   ` Robert Dewar
@ 2000-02-18  0:00   ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Dewar @ 2000-02-18  0:00 UTC (permalink / raw)


In article <o7Po4.101$m35.5175@typhoon.we.mediaone.net>,
  Pascal Martin <pascal.martin@iname.com.nospam> wrote:
> In this computer world, every integer has constraints..

Integer'Base is NOT a constrained type!


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-02-18  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-10  0:00 Constraint or what? Jan Wuyts
2000-02-10  0:00 ` reason67
2000-02-11  0:00 ` Pascal Martin
2000-02-13  0:00   ` Robert Dewar
2000-02-18  0:00   ` Robert Dewar
2000-02-16  0:00 ` Ian Ward

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