comp.lang.ada
 help / color / mirror / Atom feed
* CONSTRAINT_ERROR - why?
@ 2002-12-14 18:28 Alfred Hilscher
  2002-12-14 18:45 ` James S. Rogers
  2002-12-14 20:19 ` Jeffrey Carter
  0 siblings, 2 replies; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-14 18:28 UTC (permalink / raw)


This program raises exception CONSTRAINT_ERROR for the second
assignment. It happens with GNAT 3.13p and 3.14p (on windows).

Can someone explain why? Is this a compiler error or do I misunderstand
something?

I would expect that the computation is done first and then the result
(33 which is successfully assigned the statement before) is assigned.
But it seems that the size (=264) is assigned before the division is
executed.


with Interfaces.C; use Interfaces.C;

with Text_IO; use Text_IO;

procedure Test is

    type    BYTE       is new Interfaces.C.Unsigned_Char; 
    
    type Fac_Conf_Struct is
      record
        Struct_Length     : BYTE;
        Filler            : String (1..32);   
      end record;  


  X : Fac_Conf_Struct;
begin
  Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size /
8));
  X.Struct_Length := 33;
  X.Struct_Length := (Fac_Conf_Struct'Size / 8);  -- Value is 33, too.
But - constraint_error is raised
end Test;



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 18:28 CONSTRAINT_ERROR - why? Alfred Hilscher
@ 2002-12-14 18:45 ` James S. Rogers
  2002-12-14 19:15   ` Robert A Duff
  2002-12-14 19:20   ` Alfred Hilscher
  2002-12-14 20:19 ` Jeffrey Carter
  1 sibling, 2 replies; 35+ messages in thread
From: James S. Rogers @ 2002-12-14 18:45 UTC (permalink / raw)


"Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
news:3DFB7841.F898C02@t-online.de...
> This program raises exception CONSTRAINT_ERROR for the second
> assignment. It happens with GNAT 3.13p and 3.14p (on windows).
>
> Can someone explain why? Is this a compiler error or do I misunderstand
> something?
>
> I would expect that the computation is done first and then the result
> (33 which is successfully assigned the statement before) is assigned.
> But it seems that the size (=264) is assigned before the division is
> executed.
>
>
> with Interfaces.C; use Interfaces.C;
>
> with Text_IO; use Text_IO;
>
> procedure Test is
>
>     type    BYTE       is new Interfaces.C.Unsigned_Char;
>
>     type Fac_Conf_Struct is
>       record
>         Struct_Length     : BYTE;
>         Filler            : String (1..32);
>       end record;
>
>
>   X : Fac_Conf_Struct;
> begin
>   Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size /
> 8));
>   X.Struct_Length := 33;
>   X.Struct_Length := (Fac_Conf_Struct'Size / 8);  -- Value is 33, too.
> But - constraint_error is raised
> end Test;

It compiles and runs without exception using GNAT 3.15p.

Jim Rogers





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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 18:45 ` James S. Rogers
@ 2002-12-14 19:15   ` Robert A Duff
  2002-12-14 19:20     ` James S. Rogers
  2002-12-14 19:42     ` Alfred Hilscher
  2002-12-14 19:20   ` Alfred Hilscher
  1 sibling, 2 replies; 35+ messages in thread
From: Robert A Duff @ 2002-12-14 19:15 UTC (permalink / raw)


"James S. Rogers" <jimmaureenrogers@worldnet.att.net> writes:

> "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> news:3DFB7841.F898C02@t-online.de...
> > This program raises exception CONSTRAINT_ERROR for the second
> > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> >
> > Can someone explain why? Is this a compiler error or do I misunderstand
> > something?
> >
> > I would expect that the computation is done first and then the result
> > (33 which is successfully assigned the statement before) is assigned.
> > But it seems that the size (=264) is assigned before the division is
> > executed.

The 'Size is implicitly converted to BYTE, and then the "/" operator of
type BYTE is used.  You want to do the division in, say, Integer,
and then explicitly convert to BYTE, like:

    ... := BYTE(Integer'(Fac_Conf_Struct'Size / 8));

> > with Interfaces.C; use Interfaces.C;
> >
> > with Text_IO; use Text_IO;
> >
> > procedure Test is
> >
> >     type    BYTE       is new Interfaces.C.Unsigned_Char;
> >
> >     type Fac_Conf_Struct is
> >       record
> >         Struct_Length     : BYTE;
> >         Filler            : String (1..32);
> >       end record;
> >
> >
> >   X : Fac_Conf_Struct;
> > begin
> >   Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size /
> > 8));
> >   X.Struct_Length := 33;
> >   X.Struct_Length := (Fac_Conf_Struct'Size / 8);  -- Value is 33, too.
> > But - constraint_error is raised
> > end Test;
> 
> It compiles and runs without exception using GNAT 3.15p.

Perhaps checking is turned off?

- Bob



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 19:15   ` Robert A Duff
@ 2002-12-14 19:20     ` James S. Rogers
  2002-12-14 19:42     ` Alfred Hilscher
  1 sibling, 0 replies; 35+ messages in thread
From: James S. Rogers @ 2002-12-14 19:20 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
news:wccof7obef4.fsf@shell01.TheWorld.com...
> "James S. Rogers" <jimmaureenrogers@worldnet.att.net> writes:
>
> > "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> > news:3DFB7841.F898C02@t-online.de...
> > > This program raises exception CONSTRAINT_ERROR for the second
> > > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> > >
> > > Can someone explain why? Is this a compiler error or do I
misunderstand
> > > something?
> > >
> > > I would expect that the computation is done first and then the result
> > > (33 which is successfully assigned the statement before) is assigned.
> > > But it seems that the size (=264) is assigned before the division is
> > > executed.
>
> The 'Size is implicitly converted to BYTE, and then the "/" operator of
> type BYTE is used.  You want to do the division in, say, Integer,
> and then explicitly convert to BYTE, like:

This is what I expected.
I checked GNAT 3.15p just as a sanity check.

>
>     ... := BYTE(Integer'(Fac_Conf_Struct'Size / 8));
>
> > > with Interfaces.C; use Interfaces.C;
> > >
> > > with Text_IO; use Text_IO;
> > >
> > > procedure Test is
> > >
> > >     type    BYTE       is new Interfaces.C.Unsigned_Char;
> > >
> > >     type Fac_Conf_Struct is
> > >       record
> > >         Struct_Length     : BYTE;
> > >         Filler            : String (1..32);
> > >       end record;
> > >
> > >
> > >   X : Fac_Conf_Struct;
> > > begin
> > >   Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size /
> > > 8));
> > >   X.Struct_Length := 33;
> > >   X.Struct_Length := (Fac_Conf_Struct'Size / 8);  -- Value is 33, too.
> > > But - constraint_error is raised
> > > end Test;
> >
> > It compiles and runs without exception using GNAT 3.15p.
>
> Perhaps checking is turned off?
>
I checked that too. Nope.
Checking was not turned off.

Jim Rogers





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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 18:45 ` James S. Rogers
  2002-12-14 19:15   ` Robert A Duff
@ 2002-12-14 19:20   ` Alfred Hilscher
  2002-12-14 20:58     ` Dennis Lee Bieber
  1 sibling, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-14 19:20 UTC (permalink / raw)




"James S. Rogers" schrieb:
> 
> "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> news:3DFB7841.F898C02@t-online.de...
> > This program raises exception CONSTRAINT_ERROR for the second
> > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> 
> It compiles and runs without exception using GNAT 3.15p.
> 
> Jim Rogers


Sorry. I've downloaded and installed GNAT 3.15p,  and the exception
still comes. I've compiled with AdaGide, with "integer overflow check"
enabled.



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 19:15   ` Robert A Duff
  2002-12-14 19:20     ` James S. Rogers
@ 2002-12-14 19:42     ` Alfred Hilscher
  2002-12-16  2:39       ` AG
  1 sibling, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-14 19:42 UTC (permalink / raw)




Robert A Duff schrieb:
> 
> "James S. Rogers" <jimmaureenrogers@worldnet.att.net> writes:
> 
> > "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> > news:3DFB7841.F898C02@t-online.de...
> > > This program raises exception CONSTRAINT_ERROR for the second
> > > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> > >
> > > Can someone explain why? Is this a compiler error or do I misunderstand
> > > something?
> > >
> > > I would expect that the computation is done first and then the result
> > > (33 which is successfully assigned the statement before) is assigned.
> > > But it seems that the size (=264) is assigned before the division is
> > > executed.
> 
> The 'Size is implicitly converted to BYTE, and then the "/" operator of
> type BYTE is used.  You want to do the division in, say, Integer,
> and then explicitly convert to BYTE, like:
> 
>     ... := BYTE(Integer'(Fac_Conf_Struct'Size / 8));

Shouldn`t the conversion take place _after_ the computation? First
compute ('size /8) as universal_integer and then adopt (for the
assignment only) to the type of the right side?



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 18:28 CONSTRAINT_ERROR - why? Alfred Hilscher
  2002-12-14 18:45 ` James S. Rogers
@ 2002-12-14 20:19 ` Jeffrey Carter
  2002-12-14 22:26   ` Alfred Hilscher
  2002-12-15 14:01   ` Alfred Hilscher
  1 sibling, 2 replies; 35+ messages in thread
From: Jeffrey Carter @ 2002-12-14 20:19 UTC (permalink / raw)


Alfred Hilscher wrote:
> This program raises exception CONSTRAINT_ERROR for the second
> assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> 
> Can someone explain why? Is this a compiler error or do I misunderstand
> something?

The reason Constraint_Error is raised is because the code violates a 
constraint.

Why are you using Interfaces.C if you're not interfacing with C?

Since the LHS of your assignment is type Byte, the expression is 
evaluated using

function "/" (Left, Right : Byte) return Byte;

The value passed to Left is not in the range of Byte. If you want this 
evaluated as a universal expression, you have to add a step:

declare
    Value : constant := X'Size / 8;
begin
    Y := Value;
end;

-- 
Jeff Carter
"Why don't you bore a hole in yourself and let the sap run out?"
Horse Feathers




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 19:20   ` Alfred Hilscher
@ 2002-12-14 20:58     ` Dennis Lee Bieber
  2002-12-15 13:45       ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-14 20:58 UTC (permalink / raw)


Alfred Hilscher fed this fish to the penguins on Saturday 14 December 
2002 11:20 am:

>
> 
> Sorry. I've downloaded and installed GNAT 3.15p,  and the exception
> still comes. I've compiled with AdaGide, with "integer overflow check"
> enabled.

        Turn the check off.

        I'd expect the return of 'size to be type larger than a byte (more 
likely full integer) and the compiler may be assuming that assignment 
of an integer (regardless of current value) to a BYTE is invalid.

[wulfraed@beastie ada]$ gnatmake -v

GNATMAKE 3.15p  (20020523) Copyright 1995-2002 Free Software 
Foundation, Inc.
Usage: gnatmake  opts  name  {[-cargs opts] [-bargs opts] [-largs opts]}

[wulfraed@beastie ada]$ gnatmake -gnato test
gcc -c -gnato test.adb
gnatbind -x test.ali
gnatlink test.ali
gnatlink: warning: executable name "test" may conflict with shell 
command
[wulfraed@beastie ada]$ ./test
Struct_Length= 33

raised CONSTRAINT_ERROR : test.adb:19 overflow check failed

From the user guide:

-gnato 
   Enables overflow checking for integer operations. This causes GNAT 
to generate slower and larger executable programs by adding code to 
check for overflow (resulting in raising Constraint_Error as required 
by standard Ada semantics). These overflow checks correspond to 
situations in which the true value of the result of an operation may be 
outside the base range of the result type. The following example shows 
the distinction: 

        Without the check:

[wulfraed@beastie ada]$ touch test.adb
[wulfraed@beastie ada]$ gnatmake test
gcc -c test.adb
gnatbind -x test.ali
gnatlink test.ali
gnatlink: warning: executable name "test" may conflict with shell 
command
[wulfraed@beastie ada]$ ./test
Struct_Length= 33
[wulfraed@beastie ada]$

-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 20:19 ` Jeffrey Carter
@ 2002-12-14 22:26   ` Alfred Hilscher
  2002-12-15  0:49     ` Dennis Lee Bieber
  2002-12-15  2:18     ` Jeffrey Carter
  2002-12-15 14:01   ` Alfred Hilscher
  1 sibling, 2 replies; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-14 22:26 UTC (permalink / raw)




Jeffrey Carter schrieb:
> 
> Alfred Hilscher wrote:
> > This program raises exception CONSTRAINT_ERROR for the second
> > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> >
> > Can someone explain why? Is this a compiler error or do I misunderstand
> > something?
> 
> The reason Constraint_Error is raised is because the code violates a
> constraint.
> 
> Why are you using Interfaces.C if you're not interfacing with C?


I extracted the example from a big (really big) application where heavy
use off (hardware-) manufacturer provided dlls is done.

 
> Since the LHS of your assignment is type Byte, the expression is
> evaluated using
> 
> function "/" (Left, Right : Byte) return Byte;
> 
> The value passed to Left is not in the range of Byte. If you want this
> evaluated as a universal expression, you have to add a step:
> 
> declare
>     Value : constant := X'Size / 8;
> begin
>     Y := Value;
> end;


Is there no way to avoid this extra assignment? I expected something
like function "/" (Left, Right : universal_integer) return Byte;


> --
> Jeff Carter
> "Why don't you bore a hole in yourself and let the sap run out?"
> Horse Feathers



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 22:26   ` Alfred Hilscher
@ 2002-12-15  0:49     ` Dennis Lee Bieber
  2002-12-15  2:18     ` Jeffrey Carter
  1 sibling, 0 replies; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-15  0:49 UTC (permalink / raw)


Alfred Hilscher fed this fish to the penguins on Saturday 14 December 
2002 02:26 pm:

> 
> Is there no way to avoid this extra assignment? I expected something
> like function "/" (Left, Right : universal_integer) return Byte;
>
        The philosophy of Ada is to assume nothing.

        IE, no hidden type coercions (unlike C, FORTRAN, etc.).
with Interfaces.C; use Interfaces.C;
with Text_IO; use Text_IO;

procedure Test is

    type    BYTE       is new Interfaces.C.Unsigned_Char;

    type Fac_Conf_Struct is
      record
        Struct_Length     : BYTE;
        Filler            : String (1..32);
      end record;


  X : Fac_Conf_Struct;
begin
  Put_Line ("Struct_Length=" & Integer'Image (Fac_Conf_Struct'Size / 
8));
  X.Struct_Length := 33;
  X.Struct_Length := (BYTE(Fac_Conf_Struct'Size / 8));  -- Value is 33, 
too.
end Test;

        Note the EXPLICIT type specification! It could still cause an error 
should the result of the divide exceed the value "BYTE" can contain.


-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 22:26   ` Alfred Hilscher
  2002-12-15  0:49     ` Dennis Lee Bieber
@ 2002-12-15  2:18     ` Jeffrey Carter
  2002-12-15 18:23       ` Jeffrey Carter
  1 sibling, 1 reply; 35+ messages in thread
From: Jeffrey Carter @ 2002-12-15  2:18 UTC (permalink / raw)


Alfred Hilscher wrote:
> 
> Jeffrey Carter schrieb:
>>
>>declare
>>    Value : constant := X'Size / 8;
>>begin
>>    Y := Value;
>>end;
> 
> Is there no way to avoid this extra assignment? I expected something
> like function "/" (Left, Right : universal_integer) return Byte;

There is no "extra assignment". This is a static universal expression 
and is evaluated by the compiler. Value becomes a name for the resulting 
value (a "named number"). The block statement above is another way to write

Y := 33;

except that changes to X are handled automatically.

This is, however, a gotcha in Ada. The context of the expression helps 
determine the selection ("overload resolution") of the operator. Lots of 
people, including experienced people, expect the universal operation to 
be selected for an assignment to a variable or the initialization of an 
object, but that's not what the language rules say.

-- 
Jeff Carter
"C++ is like giving an AK-47 to a monk, shooting him
full of crack and letting him loose in a mall and
expecting him to balance your checking account
'when he has the time.'"
Drew Olbrich




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 20:58     ` Dennis Lee Bieber
@ 2002-12-15 13:45       ` Alfred Hilscher
  2002-12-15 19:04         ` Robert A Duff
  2002-12-16  1:12         ` Dennis Lee Bieber
  0 siblings, 2 replies; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-15 13:45 UTC (permalink / raw)




Dennis Lee Bieber schrieb:
> 
> From the user guide:
> 
> -gnato
>    Enables overflow checking for integer operations. This causes GNAT
> to generate slower and larger executable programs by adding code to
> check for overflow (resulting in raising Constraint_Error as required
> by standard Ada semantics). These overflow checks correspond to
> situations in which the true value of the result of an operation may be

"... the result of an operation ..." The result of the operation "/"
_does_ fit into a BYTE.

> outside the base range of the result type. The following example shows
> the distinction:



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 20:19 ` Jeffrey Carter
  2002-12-14 22:26   ` Alfred Hilscher
@ 2002-12-15 14:01   ` Alfred Hilscher
  2002-12-15 18:20     ` Jeffrey Carter
  1 sibling, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-15 14:01 UTC (permalink / raw)




Jeffrey Carter schrieb:
> The value passed to Left is not in the range of Byte. If you want this
> evaluated as a universal expression, you have to add a step:
> 
> declare
>     Value : constant := X'Size / 8;
> begin
>     Y := Value;
> end;
>
> There is no "extra assignment". This is a static universal expression 
> and is evaluated by the compiler. Value becomes a name for the resulting 
> value (a "named number"). The block statement above is another way to write


I tried, but - it does not compile: "non-static expression used in
number declaration". So it's _not_ a static expression and will generate
code which will be executed during runtime.

I discussed the "why is 'size not static?" about half a year ago in cla
(when I tried to declare a "type a is array (1..(x'size/8)) of
character").


"As longer I do Ada, as more I love C."


> --
> Jeff Carter
> "Why don't you bore a hole in yourself and let the sap run out?"
> Horse Feathers



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15 14:01   ` Alfred Hilscher
@ 2002-12-15 18:20     ` Jeffrey Carter
  2002-12-15 19:00       ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: Jeffrey Carter @ 2002-12-15 18:20 UTC (permalink / raw)


Alfred Hilscher wrote:
> 
> I tried, but - it does not compile: "non-static expression used in
> number declaration". So it's _not_ a static expression and will generate
> code which will be executed during runtime.
> 
> I discussed the "why is 'size not static?" about half a year ago in cla
> (when I tried to declare a "type a is array (1..(x'size/8)) of
> character").

Another gotcha. At least is got me.

type X is mod 2 ** 8;

Z : constant := X'Size / 8;

is fine, but

type X is mod 2 ** 8;

type Y is record
    A : X;
end record;

Z : constant := Y'Size / 8;

isn't. This is one of those cases where the compiler has the information 
and could determine the value at compile time, but the language doesn't 
allow it. 'Size is static when the prefix is a static subtype, but only 
scalar and string subtypes can be static.

GNAT 3.14p seems to have an error here, as it flags 'Size of static 
string subtypes as non-static.

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15  2:18     ` Jeffrey Carter
@ 2002-12-15 18:23       ` Jeffrey Carter
  0 siblings, 0 replies; 35+ messages in thread
From: Jeffrey Carter @ 2002-12-15 18:23 UTC (permalink / raw)


Jeffrey Carter wrote:
> 
> There is no "extra assignment". This is a static universal expression 
> and is evaluated by the compiler. Value becomes a name for the resulting 
> value (a "named number"). The block statement above is another way to write

As pointed out elsewhere, I fell into the static trap here; 'Size is not 
static in this case.

The general statement, that named number declarations do not create an 
object and impose no run-time overhead, is correct (I think :).

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15 18:20     ` Jeffrey Carter
@ 2002-12-15 19:00       ` Alfred Hilscher
  2002-12-16  1:16         ` Dennis Lee Bieber
  0 siblings, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-15 19:00 UTC (permalink / raw)




Jeffrey Carter schrieb:
> 
> 
> type X is mod 2 ** 8;
> 
> Z : constant := X'Size / 8;
> 
> is fine, but
> 
> type X is mod 2 ** 8;
> 
> type Y is record
>     A : X;
> end record;
> 
> Z : constant := Y'Size / 8;


I tried to build this (with AdaGide 6.43):

procedure Test3 is

  type X is mod 2 ** 8;
  
  Y : Integer; 
begin
  declare
      Value : constant := X'Size / 8;
  begin
      Y := Value;
  end;
end Test3;

The link failed: "undefined reference to `_ada_test3'"

What happened here?

Even a simple:

procedure T is
begin
  null;
end T;

failed.



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15 13:45       ` Alfred Hilscher
@ 2002-12-15 19:04         ` Robert A Duff
  2002-12-16  1:12         ` Dennis Lee Bieber
  1 sibling, 0 replies; 35+ messages in thread
From: Robert A Duff @ 2002-12-15 19:04 UTC (permalink / raw)


Alfred Hilscher <Alfred.Hilscher@t-online.de> writes:

> Dennis Lee Bieber schrieb:
> > 
> > From the user guide:
> > 
> > -gnato
> >    Enables overflow checking for integer operations. This causes GNAT
> > to generate slower and larger executable programs by adding code to
> > check for overflow (resulting in raising Constraint_Error as required
> > by standard Ada semantics). These overflow checks correspond to
> > situations in which the true value of the result of an operation may be
> 
> "... the result of an operation ..." The result of the operation "/"
> _does_ fit into a BYTE.

The Constraint_Error comes from the implicit conversion from universal
integer to BYTE, which happens to the *operands* of "/".  It's got
nothing to do with the "/" itself.

It's a Range_Check, by the way, not an Overflow_Check.  I don't know if
the -gnato switch understands that.

The relevant RM paragraph is 4.6(28).  It is a mistake, in my opinion
(although I didn't realize it at the time).  All the other operations on
modular types wrap around -- clearly type conversion should work the
same way.  (Randy will say that *none* of the operations should wrap
around, and I could go along with that, too.  But have one "gotcha"
operation work differently from all the rest is poor language design.)

> > outside the base range of the result type. The following example shows
> > the distinction:

- Bob



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15 13:45       ` Alfred Hilscher
  2002-12-15 19:04         ` Robert A Duff
@ 2002-12-16  1:12         ` Dennis Lee Bieber
  2002-12-16  2:20           ` Jeffrey Carter
  1 sibling, 1 reply; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-16  1:12 UTC (permalink / raw)


Alfred Hilscher fed this fish to the penguins on Sunday 15 December 
2002 05:45 am:

> 
> 
> Dennis Lee Bieber schrieb:
>> 
>> From the user guide:
>> 
>> -gnato
>>    Enables overflow checking for integer operations. This causes GNAT
>> to generate slower and larger executable programs by adding code to
>> check for overflow (resulting in raising Constraint_Error as required
>> by standard Ada semantics). These overflow checks correspond to
>> situations in which the true value of the result of an operation may
>> be
> 
> "... the result of an operation ..." The result of the operation "/"
> _does_ fit into a BYTE.
> 
>> outside the base range of the result type. The following example
>> shows the distinction:

        You stopped short of " *may* be outside"... I'll concede that I'd have 
thought the compiler could have made the determination -- given that 
the size of Fac_Conf_Struct is fixed at compile time. However, I expect 
the 'Size returns a value defined in some "type" (call it "size_type") 
which is probably 32-bit integer. So you have a 32-bit integer divided 
by an anoymous integer; the result of that division, based solely on 
the data types, /could/ exceed the result type BYTE.

-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-15 19:00       ` Alfred Hilscher
@ 2002-12-16  1:16         ` Dennis Lee Bieber
  2002-12-16 18:50           ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-16  1:16 UTC (permalink / raw)


Alfred Hilscher fed this fish to the penguins on Sunday 15 December 
2002 11:00 am:

> 
> I tried to build this (with AdaGide 6.43):
> 
> procedure Test3 is
> 
        <snip> 

> The link failed: "undefined reference to `_ada_test3'"
> 
> What happened here?
> 
> Even a simple:
> 
> procedure T is
> begin
>   null;
> end T;
> 
> failed.

        What name did you give the source file when you saved it in AdaGIDE?

-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16  1:12         ` Dennis Lee Bieber
@ 2002-12-16  2:20           ` Jeffrey Carter
  2002-12-16 18:48             ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: Jeffrey Carter @ 2002-12-16  2:20 UTC (permalink / raw)


Dennis Lee Bieber wrote:
> 
>         You stopped short of " *may* be outside"... I'll concede that I'd have 
> thought the compiler could have made the determination -- given that 
> the size of Fac_Conf_Struct is fixed at compile time. However, I expect 
> the 'Size returns a value defined in some "type" (call it "size_type") 
> which is probably 32-bit integer. So you have a 32-bit integer divided 
> by an anoymous integer; the result of that division, based solely on 
> the data types, /could/ exceed the result type BYTE.

'Size returns a universal integer, which is also the type of any integer 
literal or named number.

-- 
Jeff Carter
"Don't knock masturbation. It's sex with someone I love."
Annie Hall




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-14 19:42     ` Alfred Hilscher
@ 2002-12-16  2:39       ` AG
  0 siblings, 0 replies; 35+ messages in thread
From: AG @ 2002-12-16  2:39 UTC (permalink / raw)



"Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
news:3DFB89BF.323CB3E3@t-online.de...
>
>
> Robert A Duff schrieb:
> >
> > "James S. Rogers" <jimmaureenrogers@worldnet.att.net> writes:
> >
> > > "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> > > news:3DFB7841.F898C02@t-online.de...
> > > > This program raises exception CONSTRAINT_ERROR for the second
> > > > assignment. It happens with GNAT 3.13p and 3.14p (on windows).
> > > >
> > > > Can someone explain why? Is this a compiler error or do I
misunderstand
> > > > something?
> > > >
> > > > I would expect that the computation is done first and then the
result
> > > > (33 which is successfully assigned the statement before) is
assigned.
> > > > But it seems that the size (=264) is assigned before the division is
> > > > executed.
> >
> > The 'Size is implicitly converted to BYTE, and then the "/" operator of
> > type BYTE is used.  You want to do the division in, say, Integer,
> > and then explicitly convert to BYTE, like:
> >
> >     ... := BYTE(Integer'(Fac_Conf_Struct'Size / 8));
>
> Shouldn`t the conversion take place _after_ the computation?

No. Because you need to know *which* division to use.
And that depends on the types used ...





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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16  2:20           ` Jeffrey Carter
@ 2002-12-16 18:48             ` Alfred Hilscher
  2002-12-16 19:53               ` James S. Rogers
  0 siblings, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-16 18:48 UTC (permalink / raw)




Jeffrey Carter schrieb:
> 'Size returns a universal integer, which is also the type of any integer
> literal or named number.

So why is the computation not done with function "/" (a,b :
universal_integer) return BYTE ? Why is it done with function "/" (a,b :
BYTE) return BYTE ?



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16  1:16         ` Dennis Lee Bieber
@ 2002-12-16 18:50           ` Alfred Hilscher
  2002-12-17  2:17             ` Dennis Lee Bieber
  0 siblings, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-16 18:50 UTC (permalink / raw)




Dennis Lee Bieber schrieb:
> 
> Alfred Hilscher fed this fish to the penguins on Sunday 15 December
> 2002 11:00 am:
> 
> >
> > I tried to build this (with AdaGide 6.43):
> >
> > procedure Test3 is
> >
>         <snip>
> 
> > The link failed: "undefined reference to `_ada_test3'"
> >
> > What happened here?
> >
> > Even a simple:
> >
> > procedure T is
> > begin
> >   null;
> > end T;
> >
> > failed.
> 
>         What name did you give the source file when you saved it in AdaGIDE?
> 

The first is stored in test3.adb and the second in t.adb



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16 18:48             ` Alfred Hilscher
@ 2002-12-16 19:53               ` James S. Rogers
  2002-12-17 18:20                 ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: James S. Rogers @ 2002-12-16 19:53 UTC (permalink / raw)


"Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
news:3DFE1FFB.E1BB660E@t-online.de...
>
>
> Jeffrey Carter schrieb:
> > 'Size returns a universal integer, which is also the type of any integer
> > literal or named number.
>
> So why is the computation not done with function "/" (a,b :
> universal_integer) return BYTE ? Why is it done with function "/" (a,b :
> BYTE) return BYTE ?

This is because the only "/" function defined for the Byte type is
function "/"(left, right : Byte) return Byte;

Jim Rogers





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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16 18:50           ` Alfred Hilscher
@ 2002-12-17  2:17             ` Dennis Lee Bieber
  2002-12-17 18:21               ` Alfred Hilscher
  0 siblings, 1 reply; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-17  2:17 UTC (permalink / raw)


Alfred Hilscher fed this fish to the penguins on Monday 16 December 
2002 10:50 am:

> 
> The first is stored in test3.adb and the second in t.adb

        Guess I'll have to try it when I'm in W98 next... Just emailed the 
relevant posts to my other account so I'll see them at that time.


-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-16 19:53               ` James S. Rogers
@ 2002-12-17 18:20                 ` Alfred Hilscher
  2002-12-17 19:29                   ` Robert A Duff
  0 siblings, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-17 18:20 UTC (permalink / raw)




"James S. Rogers" schrieb:
> 
> "Alfred Hilscher" <Alfred.Hilscher@t-online.de> wrote in message
> news:3DFE1FFB.E1BB660E@t-online.de...
> >
> >
> > Jeffrey Carter schrieb:
> > > 'Size returns a universal integer, which is also the type of any integer
> > > literal or named number.
> >
> > So why is the computation not done with function "/" (a,b :
> > universal_integer) return BYTE ? Why is it done with function "/" (a,b :
> > BYTE) return BYTE ?
> 
> This is because the only "/" function defined for the Byte type is
> function "/"(left, right : Byte) return Byte;


So could it be a way if I define a function "/" (a, b : Integer) return
BYTE within my code? Or wouldn`t it be used?

 
> Jim Rogers



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-17  2:17             ` Dennis Lee Bieber
@ 2002-12-17 18:21               ` Alfred Hilscher
       [not found]                 ` <26tuvu4ekeigls0bnd2okavrdhfu0tir4a@4ax.com>
  0 siblings, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-17 18:21 UTC (permalink / raw)




Dennis Lee Bieber schrieb:
> 
> Alfred Hilscher fed this fish to the penguins on Monday 16 December
> 2002 10:50 am:
> 
> >
> > The first is stored in test3.adb and the second in t.adb
> 
>         Guess I'll have to try it when I'm in W98 next... Just emailed the
> relevant posts to my other account so I'll see them at that time.


I work on Windows NT 4.0



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-17 18:20                 ` Alfred Hilscher
@ 2002-12-17 19:29                   ` Robert A Duff
  2002-12-17 21:05                     ` Dennis Lee Bieber
  2002-12-18 18:36                     ` Alfred Hilscher
  0 siblings, 2 replies; 35+ messages in thread
From: Robert A Duff @ 2002-12-17 19:29 UTC (permalink / raw)


Alfred Hilscher <Alfred.Hilscher@t-online.de> writes:

> So could it be a way if I define a function "/" (a, b : Integer) return
> BYTE within my code? Or wouldn`t it be used?

Probably both "/" operators would be directly visible,
so it would be ambiguous.  What's wrong with this:

    X.Struct_Length := BYTE(Integer'(Fac_Conf_Struct'Size / 8));

or perhaps:

    X.Struct_Length := BYTE(Integer'(X'Size / System.Storage_Unit));
    pragma Assert(X.Struct_Length*System.Storage_Unit = X'Size);
    -- Assert that it's an integer number of storage units.

or even:

    generic
        type T is limited private;
    function Size_In_Storage_Elements return BYTE;

    function Size_In_Storage_Elements return BYTE is
        Result: constant BYTE := BYTE(Integer'(T'Size / System.Storage_Unit));
    begin
        pragma Assert(Result*System.Storage_Unit = X'Size);
        return Result;
    end Size_In_Storage_Elements;

- Bob



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-17 19:29                   ` Robert A Duff
@ 2002-12-17 21:05                     ` Dennis Lee Bieber
  2002-12-18 18:36                     ` Alfred Hilscher
  1 sibling, 0 replies; 35+ messages in thread
From: Dennis Lee Bieber @ 2002-12-17 21:05 UTC (permalink / raw)


Robert A Duff fed this fish to the penguins on Tuesday 17 December 2002 
11:29 am:

> 
>     X.Struct_Length := BYTE(Integer'(Fac_Conf_Struct'Size / 8));
>
        My quick test indicates that just BYTE(Fac_Conf_Struct'Size / 8) is 
sufficient to escape the overflow check.

-- 
 > ============================================================== <
 >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed@dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-17 19:29                   ` Robert A Duff
  2002-12-17 21:05                     ` Dennis Lee Bieber
@ 2002-12-18 18:36                     ` Alfred Hilscher
  2002-12-18 18:51                       ` Robert A Duff
  1 sibling, 1 reply; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-18 18:36 UTC (permalink / raw)




Robert A Duff schrieb:
> 
> Alfred Hilscher <Alfred.Hilscher@t-online.de> writes:
> 
> > So could it be a way if I define a function "/" (a, b : Integer) return
> > BYTE within my code? Or wouldn`t it be used?
> 
> Probably both "/" operators would be directly visible,
> so it would be ambiguous.  What's wrong with this:
> 
>     X.Struct_Length := BYTE(Integer'(Fac_Conf_Struct'Size / 8));


I have written a lot of code and there a many such assignments, because
the (C-)interface expects always the first component of a structure to
contain the structure length in bytes. So I want reduce the effort to
change the code. 
The main problem is, that GNAT does the compile without error and
without warning (at least when invoked from AdaGide), and the exception
is detected only during runtime (Aonix shows a warning during
compilation). I had to write a lot of code before I could do the first
run. If I'd got an warning during compilation then the problem had been
detected in an early phase and the changes were minimal.



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

* Re: CONSTRAINT_ERROR - why?
       [not found]                 ` <26tuvu4ekeigls0bnd2okavrdhfu0tir4a@4ax.com>
@ 2002-12-18 18:47                   ` Alfred Hilscher
  0 siblings, 0 replies; 35+ messages in thread
From: Alfred Hilscher @ 2002-12-18 18:47 UTC (permalink / raw)




Dennis Lee Bieber schrieb:
>          (I think I'm a bit behind -- I have
> downloaded the 7.x AdaGIDE and GNAT 3.15p, but haven't installed them)

Me, too.
 
> GNAT 3.14p  (20010503) Copyright 1992-2001 Free Software Foundation,
> Inc.
> 
> Compiling: e:\t.adb (source file time stamp: 2002-12-17 18:39:28)
> 
>      1. procedure T is
>      2.
>      3. begin
>      4.    null;
>      5. end T;
> 
>  5 lines: No errors
> 
>         And runs, though all it does is open a command line shell, and
> then a pop-up to close.


I compiled it is a DOS-window by simply typing "gnatmake test3.adb" and
it works well. When I select "build - F3" from the AdaGide menu then I
get the error during gnatlink:"b~test3.o(.test+0x9f):b~test3.adb:
undefined reference to _ada_test3'".

Ok, this is mysterious but not really problematic. Thanks.



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-18 18:36                     ` Alfred Hilscher
@ 2002-12-18 18:51                       ` Robert A Duff
  2002-12-18 21:45                         ` Randy Brukardt
  0 siblings, 1 reply; 35+ messages in thread
From: Robert A Duff @ 2002-12-18 18:51 UTC (permalink / raw)


Alfred Hilscher <Alfred.Hilscher@t-online.de> writes:

> I have written a lot of code and there a many such assignments, because
> the (C-)interface expects always the first component of a structure to
> contain the structure length in bytes. So I want reduce the effort to
> change the code. 

You're trying to convert a size in bits (of type universal_integer) to a
size in bytes (of type BYTE).  And you're doing that all over the place.
So it seems to me you should encapsulate that operation.  It's not hard
to write a function to do that.  I also suggested a generic, which is a
bit heavy, but does the job.  Yes, you'll have to change all your code
to refer to the encapsulated operation.

> The main problem is, that GNAT does the compile without error and
> without warning (at least when invoked from AdaGide), and the exception
> is detected only during runtime (Aonix shows a warning during
> compilation). I had to write a lot of code before I could do the first
> run. If I'd got an warning during compilation then the problem had been
> detected in an early phase and the changes were minimal.

Yes, I agree this is a language design flaw.  I'm glad to hear the Aonix
compiler at least gave a warning (since I work for SofCheck, and Aonix
uses SofCheck's AdaMagic front end).

(Modular types are one of my least favorite features of Ada 95.)

- Bob



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

* Re: CONSTRAINT_ERROR - why?
  2002-12-18 18:51                       ` Robert A Duff
@ 2002-12-18 21:45                         ` Randy Brukardt
  2002-12-19 16:49                           ` Robert Spooner
  0 siblings, 1 reply; 35+ messages in thread
From: Randy Brukardt @ 2002-12-18 21:45 UTC (permalink / raw)



Robert A Duff wrote in message ...
>You're trying to convert a size in bits (of type universal_integer) to
a
>size in bytes (of type BYTE).  And you're doing that all over the
place.
>So it seems to me you should encapsulate that operation.  It's not hard
>to write a function to do that.  I also suggested a generic, which is a
>bit heavy, but does the job.  Yes, you'll have to change all your code
>to refer to the encapsulated operation.

Bob didn't mention that your code isn't even right (ignoring the
overflow issue). You have to take care when doing this conversion to
round up, because the 'Size value may not be a multiple of the byte
size. (Boolean'Size = 1, for instance.) So your code should really be:

    X.Struct_Length := BYTE(Integer'((Fac_Conf_Struct'Size+7) / 8));

But, then that could be a problem if it ever needs to run on a system
with a byte size other than 8. (We ran into this when hosting Janus/Ada
on the U2200). So we ended up using constants for this:

 package Host is
    IO_BIT_SIZE : Constant := 8;
        -- Size, in bits, of the basic I/O element.
    IO_ROUNDING_SIZE : Constant := IO_BIT_SIZE - 1;
        -- Size to round bits by; usually added to a 'Size value.
    ...
 end Host;

and then your expression would look like:
    X.Struct_Length :=
BYTE(Integer'((Fac_Conf_Struct'Size+Host.IO_ROUNDING_SIZE) /
Host.IO_BIT_SIZE));

Making this a subprogram hides most of this, and makes it much easier to
change if you need to do so. I wish we had done that in the first place.

(We called these IO_Bit_Size, because most of these expressions occur
doing I/O. In Ada 95, you'd do that with Streams, so this code could go
in the junk [where it belongs]. There is a separate constant for target
byte sizes, because the I/O element size may not be the same as the byte
size (i.e. Stream_Element'Size does not need to be the same as
Storage_Element'Size).

             Randy.









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

* Re: CONSTRAINT_ERROR - why?
  2002-12-18 21:45                         ` Randy Brukardt
@ 2002-12-19 16:49                           ` Robert Spooner
  2002-12-19 20:57                             ` Randy Brukardt
  0 siblings, 1 reply; 35+ messages in thread
From: Robert Spooner @ 2002-12-19 16:49 UTC (permalink / raw)


Another way is to use the Max_Size_In_Storage_Elements attribute.

Randy Brukardt wrote:
> ...
>     X.Struct_Length := BYTE(Integer'((Fac_Conf_Struct'Size+7) / 8));
> ...
-- 
                             Robert L. Spooner
                      Registered Professional Engineer
                        Associate Research Engineer
                   Intelligent Control Systems Department

          Applied Research Laboratory        Phone: (814) 863-4120
          The Pennsylvania State University  FAX:   (814) 863-7841
          P. O. Box 30
          State College, PA 16804-0030       rls19@psu.edu




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

* Re: CONSTRAINT_ERROR - why?
  2002-12-19 16:49                           ` Robert Spooner
@ 2002-12-19 20:57                             ` Randy Brukardt
  0 siblings, 0 replies; 35+ messages in thread
From: Randy Brukardt @ 2002-12-19 20:57 UTC (permalink / raw)


Robert Spooner wrote in message <3E01F897.20404@psu.edu>...
>Another way is to use the Max_Size_In_Storage_Elements attribute.


In general, that could be dangerous, at least when writing to the
object. Because that is the maximum number of bytes that could ever for
some object of the subtype, and nothing requires compilers to make it
accurate. Storage_Elements.Storage_Count'Last is always a correct
response for this attribute (and in some cases, the only possible
response). Also, if the object is stored in multiple parts, it might
actually be bigger than than this value.

So this value could be larger than the actual object. Obj'Size is the
safest way to find out, but then you must take care to round properly,
etc.

             Randy.






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

end of thread, other threads:[~2002-12-19 20:57 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-14 18:28 CONSTRAINT_ERROR - why? Alfred Hilscher
2002-12-14 18:45 ` James S. Rogers
2002-12-14 19:15   ` Robert A Duff
2002-12-14 19:20     ` James S. Rogers
2002-12-14 19:42     ` Alfred Hilscher
2002-12-16  2:39       ` AG
2002-12-14 19:20   ` Alfred Hilscher
2002-12-14 20:58     ` Dennis Lee Bieber
2002-12-15 13:45       ` Alfred Hilscher
2002-12-15 19:04         ` Robert A Duff
2002-12-16  1:12         ` Dennis Lee Bieber
2002-12-16  2:20           ` Jeffrey Carter
2002-12-16 18:48             ` Alfred Hilscher
2002-12-16 19:53               ` James S. Rogers
2002-12-17 18:20                 ` Alfred Hilscher
2002-12-17 19:29                   ` Robert A Duff
2002-12-17 21:05                     ` Dennis Lee Bieber
2002-12-18 18:36                     ` Alfred Hilscher
2002-12-18 18:51                       ` Robert A Duff
2002-12-18 21:45                         ` Randy Brukardt
2002-12-19 16:49                           ` Robert Spooner
2002-12-19 20:57                             ` Randy Brukardt
2002-12-14 20:19 ` Jeffrey Carter
2002-12-14 22:26   ` Alfred Hilscher
2002-12-15  0:49     ` Dennis Lee Bieber
2002-12-15  2:18     ` Jeffrey Carter
2002-12-15 18:23       ` Jeffrey Carter
2002-12-15 14:01   ` Alfred Hilscher
2002-12-15 18:20     ` Jeffrey Carter
2002-12-15 19:00       ` Alfred Hilscher
2002-12-16  1:16         ` Dennis Lee Bieber
2002-12-16 18:50           ` Alfred Hilscher
2002-12-17  2:17             ` Dennis Lee Bieber
2002-12-17 18:21               ` Alfred Hilscher
     [not found]                 ` <26tuvu4ekeigls0bnd2okavrdhfu0tir4a@4ax.com>
2002-12-18 18:47                   ` Alfred Hilscher

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