|
From: Mike Silva on 12 Jun 2008 12:43 On Jun 12, 4:45 am, Markus Schoepflin <nos...(a)no.spam> wrote: > > Both GNAT and Dec Ada return 1 and 2 for both A1 and A2, so they are > correctly debiasing when explicitly asked for the internal representation. > > Markus Now I'm really confused. In your OP you showed some "incorrect" binary values - how did you get those values? By inspecting memory? Now you talk about explicitly asking for the internal representation. What does that mean exactly? Are you saying now that there's no problem after all? Mike
From: Markus Schöpflin on 12 Jun 2008 14:41 Mike Silva schrieb: > On Jun 12, 4:45 am, Markus Schoepflin <nos...(a)no.spam> wrote: >> Both GNAT and Dec Ada return 1 and 2 for both A1 and A2, so they are >> correctly debiasing when explicitly asked for the internal representation. >> >> Markus > > Now I'm really confused. In your OP you showed some "incorrect" > binary values - how did you get those values? By inspecting memory? Yes. > Now you talk about explicitly asking for the internal representation. > What does that mean exactly? Using unchecked conversion to ask for the value of the variables. > Are you saying now that there's no problem after all? Not at all. The memory layout of the variables is not what I expect it to be, because the compiler silently biased those values. The compiler is perfectly aware of this, as it makes up for the biasing when explicitly querying the value, but this doesn't help at all because I'm interested in the exact bitwise representation. Admittedly, there is an inconsistency in what I'm asking the compiler to do, but that's the whole point: I do not want this inconsistency to be silently 'fixed' by the compiler, I want to get noted about my error to get a chance and fix it myself. > Mike Regards, Markus
From: richtmyer on 12 Jun 2008 15:05 On Jun 11, 7:38 am, Markus Schoepflin <nos...(a)no.spam> wrote: > Hello, > > please consider the following code snippet: etc ----- Interesting. I had been playing with a similar example, and have modified it a bit to present. What got me is the record type with length 1 but an object with that type that was length zero! (It compiles without any warnings). ------------------------------ test1.2.ada -------------------------------------- -- -- GPS 4.2.1 (20080115) hosted on pentium-mingw32msv -- GNAT GPL 2007 (20070405-41) -- -- X_Type'size = 31 -- X_Rec_Type'size = 32 -- X_Rec'size = 32 -- Y_Rec_Type'size = 1 -- Y_Rec'size = 8 -- X_Rec.X1 = 2147483647 -- Y_Rec.X1 = 2147483647 -- GPS Pro 4.1.1 (20070423) hosted on i686-pc-linux-gnu -- GNAT Pro 6.1.1 (20080111-41) -- -- X_Type'size = 31 -- X_Rec_Type'size = 32 -- X_Rec'size = 32 -- Y_Rec_Type'size = 1 -- Y_Rec'size = 0 -- this object is smaller than its type! -- X_Rec.X1 = 2147483647 -- Y_Rec.X1 = 2147483647 ------------------------------------------------------------------------- with ada.exceptions; use ada.exceptions; with interfaces.c; with text_io; use text_io; with unchecked_conversion; procedure test1 is type X_Type is ( X ); for x_type use (x => 16#7FFF_FFFF#); type X_Rec_Type is Record X1 : X_Type; End Record; X_Rec : X_Rec_Type := (X1 => x); type Y_Rec_Type is Record X1 : X_Type; End Record; for Y_Rec_Type'size use 0; for Y_Rec_Type use Record X1 at 0 range 0 .. -1; -- Minus 1 !! End Record; Y_Rec : Y_Rec_Type := (X1 => X); function convert is new unchecked_conversion (X_type, natural); begin put_line("X_Type'size = " & X_Type'size'img); put_line("X_Rec_Type'size = " & X_Rec_Type'size'img); put_line("X_Rec'size = " & X_Rec'size'img); put_line("Y_Rec_Type'size = " & Y_Rec_Type'size'img); put_line("Y_Rec'size = " & Y_Rec'size'img); put_line("X_Rec.X1 = " & convert(X_Rec.X1)'img); put_line("Y_Rec.X1 = " & convert(Y_Rec.X1)'img); end test1;
From: Mike Silva on 12 Jun 2008 16:10 On Jun 12, 2:41 pm, Markus Schöpflin <nos...(a)nospam.org> wrote: > Mike Silva schrieb: > > > On Jun 12, 4:45 am, Markus Schoepflin <nos...(a)no.spam> wrote: > >> Both GNAT and Dec Ada return 1 and 2 for both A1 and A2, so they are > >> correctly debiasing when explicitly asked for the internal representation. > > >> Markus > > > Now I'm really confused. In your OP you showed some "incorrect" > > binary values - how did you get those values? By inspecting memory? > > Yes. > > > Now you talk about explicitly asking for the internal representation. > > What does that mean exactly? > > Using unchecked conversion to ask for the value of the variables. > > > Are you saying now that there's no problem after all? > > Not at all. The memory layout of the variables is not what I expect it > to be, because the compiler silently biased those values. The compiler > is perfectly aware of this, as it makes up for the biasing when > explicitly querying the value, but this doesn't help at all because I'm > interested in the exact bitwise representation. > > Admittedly, there is an inconsistency in what I'm asking the compiler to > do, but that's the whole point: I do not want this inconsistency to be > silently 'fixed' by the compiler, I want to get noted about my error to > get a chance and fix it myself. I wonder then if this is an error at all. IANALL, but if the program makes available your specified values when queried with the proper mechanism (in this case, unchecked conversion), then I don't see what difference it makes how it stores the representations in raw memory. I'd welcome other comments on the validity or non-validity of this view. Mike
From: Simon Wright on 12 Jun 2008 16:52
Mike Silva <snarflemike(a)yahoo.com> writes: > I wonder then if this is an error at all. IANALL, but if the > program makes available your specified values when queried with the > proper mechanism (in this case, unchecked conversion), then I don't > see what difference it makes how it stores the representations in > raw memory. The only reason I have ever written representation clauses is to ensure that the contents of raw memory are what some external hardware (or software, eg at the other end of a network connection) requires them to be. So I really really don't want the compiler to do anything other than what I asked for; and if it can't, to reject the representation loudly and fatally! Given OP's declarations type Enum_T is (One, Two); for Enum_T use (One => 1, Two => 2); type Record_T is record A1 : Enum_T; A2 : Enum_T; end record; for Record_T use record A1 at 0 range 0 .. 0; A2 at 1 range 0 .. 7; end record; for Record_T'Size use 2 * 8; Foo : Record_T; there's a huge difference between an unchecked conversion of the value Foo.A1 to <whatever>, which might quite reasonably have the bias removed, and UC of the value Foo as a whole, which wouldn't. |