comp.lang.ada
 help / color / mirror / Atom feed
* Is this a GNAT bug???
@ 2002-04-26 16:36 Robert Quinn
  2002-04-26 17:48 ` Mark Johnson
  0 siblings, 1 reply; 21+ messages in thread
From: Robert Quinn @ 2002-04-26 16:36 UTC (permalink / raw)


I originally posted a question regarding pragma pack, but after
stripping away all the details I found what may be a bug, or just
something I don't understand about low level programming.  I will post
it, and it is brief code, but in a nutshell an array of 64 bits packs
fine, but an array of 65 bits does not!

I will post code here that is actually compilable, unlike my last
message :)

I am using gnat3.13p on Sparc Solaris

Here is the WORKING, NO ERRORS code:

package test is
   type ONE_BIT_TYPE is range 0..1;
   for ONE_BIT_TYPE'SIZE use 1;

   type ARRAY_OF_64_BITS_TYPE is array (1..64) of ONE_BIT_TYPE;
   pragma pack (ARRAY_OF_BITS_TYPE);

   type MY_TYPE is record
      ARRAY_OF_64_BITS : ARRAY_OF_64_BITS_TYPE;
   end record;

   pragma pack (MY_TYPE);

   for MY_TYPE use record
      ARRAY_OF_64_BITS at 0 range 0..63;
   end record;

end test;

** NOW just replace 64 with 65 (and 63 with 64 on range) and Voila',
you get the error:
  "size of ARRAY_OF_65_BITS too small, minimum allowed is 72"

Here is the OFFENDING code:

package test is
   type ONE_BIT_TYPE is range 0..1;
   for ONE_BIT_TYPE'SIZE use 1;

   type ARRAY_OF_65_BITS_TYPE is array (1..65) of ONE_BIT_TYPE;
   pragma pack (ARRAY_OF_BITS_TYPE);

   type MY_TYPE is record
      ARRAY_OF_65_BITS : ARRAY_OF_65_BITS_TYPE;
   end record;

   pragma pack (MY_TYPE);

   for MY_TYPE use record
      ARRAY_OF_65_BITS at 0 range 0..64;
   end record;

end test;


So why can't I pack a bit array of 65 bits or more bits? Anyone have
any comments?



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Is this a gnat bug?
@ 2003-09-20 22:50 Waldek Hebisch
  2003-09-20 23:09 ` Ludovic Brenta
  2003-09-21  2:37 ` Waldek Hebisch
  0 siblings, 2 replies; 21+ messages in thread
From: Waldek Hebisch @ 2003-09-20 22:50 UTC (permalink / raw)


I am trying to convert a sequence of eight bytes to a fixed point
number. For testing I put bytes in an array. I first collect bytes
in a modular type and then assign the result to an integer (I have
eight bytes in big endian order, but the actual number should be
small). When number formed from 4 lower order bytes is out of
range I get CONSTRAINT_ERROR but if only higher order bytes are
non-zero I get just zero result. I would expect CONSTRAINT_ERROR 
always when any of higher order bytes is non-zero. With both 
gnat-3.14p and gnat from gcc-3.3 the program below prints huge
number for 'pp' and 0.0 for 'price'. 

with Ada.Text_IO;

procedure tstnum is 
type fx15_2 is delta 0.01 range -9999999999999.99 .. 9999999999999.99 ;
type price_type is delta 0.01 digits 6;

procedure getnum(num : out price_type) is 
  type ll is mod 2**64;
  type ip is range 0 .. 1000000 ;
  type byteind is range 0 .. 7;
  bytes : array (byteind) of integer range 0 .. 255 := (0..3 => 247 , 4..7=>0);
  pp : ll := 0 ;
  pp1 : ip;
begin
        for i in bytes'range loop
	        pp := pp * 256;
		pp := pp + ll(bytes(i));
	end loop;
	Ada.Text_IO.Put_Line("pp = " & ll'image(pp));
	pp1 := ip(pp); -- Should range check ??
	num := price_type(fx15_2(pp1)/100);
end;

price : price_type;

begin
	getnum(price);
	Ada.Text_IO.Put_Line("price = " & price_type'image(price));
end tstnum;


--
                              Waldek Hebisch
hebisch@math.uni.wroc.pl    or hebisch@hera.math.uni.wroc.pl 



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

end of thread, other threads:[~2003-09-21  2:37 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-26 16:36 Is this a GNAT bug??? Robert Quinn
2002-04-26 17:48 ` Mark Johnson
2002-04-26 22:20   ` Robert Dewar
2002-04-29 15:45   ` Robert Quinn
2002-04-30  2:44     ` Robert Dewar
2002-04-30 14:15       ` Larry Kilgallen
2002-04-30 16:41       ` Robert Quinn
2002-04-30 18:20         ` tmoran
2002-05-01  1:31           ` Robert Quinn
2002-05-01 17:08             ` Ted Dennison
2002-05-02  1:55               ` Larry Kilgallen
2002-05-02 14:04                 ` Mark Johnson
2002-05-02 15:25                   ` Larry Kilgallen
2002-04-30 21:55         ` Mark Johnson
2002-05-01 22:59           ` Nick Roberts
2002-05-02 13:56             ` Mark Johnson
2002-05-02 20:19               ` Nick Roberts
2002-05-02 21:55                 ` Mark Johnson
  -- strict thread matches above, loose matches on Subject: below --
2003-09-20 22:50 Is this a gnat bug? Waldek Hebisch
2003-09-20 23:09 ` Ludovic Brenta
2003-09-21  2:37 ` Waldek Hebisch

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