From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,79db4ff72bff9422 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-30 20:10:27 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: byhoe@greenlime.com (Adrian Hoe) Newsgroups: comp.lang.ada Subject: Re: How to convert record? Date: 30 Oct 2001 20:10:27 -0800 Organization: http://groups.google.com/ Message-ID: <9ff447f2.0110302010.48335e74@posting.google.com> References: NNTP-Posting-Host: 210.186.172.94 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1004501427 13628 127.0.0.1 (31 Oct 2001 04:10:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 31 Oct 2001 04:10:27 GMT Xref: archiver1.google.com comp.lang.ada:15461 Date: 2001-10-31T04:10:27+00:00 List-Id: "Beard, Frank" wrote in message news:... > But using this method it doesn't matter whether it's packed > or not, or whether it's 14 or 11 bytes. the_Command'size > will give you the size of the "object" being passed in, which > will be translated to the equivalent size IO_Buffer. So long > as the receiver is on the same platform (same hardware and > same OS), or represents the data the same way, it will work. > So, there is no need to "take care of" the_Command'Size. > > Frank > You are wrong. Try compile the following example and you will get 14 and 16 for each. ------------------------------------------------------- with Ada.Text_Io; use Ada.Text_Io; with Ada.Integer_Text_Io; use Ada.Integer_Text_Io; procedure Test2 is type Rx_Header_Data is record Start_Byte : Character; Splitter : Character; Command_Byte : Character; Pad_Byte_1 : Character; Pad_Byte_2 : Character; Log_Num : Long_Integer; End_Byte : Character; LRC : Character; end record; -- pragma Pack (Rx_Header_Data); Command : Rx_Header_Data; procedure Print_Size (Command : in Rx_Header_Data) is begin New_Line; Put (Command'Size / 8); end Print_Size; begin Command.Start_Byte := Character'Val (2); Put (Rx_Header_Data'Size / 8); New_Line; Put (Command'Size / 8); Print_Size (Command); end Test2; ------------------------------------------------------------------ Uncomment the "pragma pack (Rx_Header_Data);", compile again and run the program and you will get 11. 11 bytes is exactly the length of the actual record. Your method "could" lead to errors if the purpose is to interface to external devices which require exactly 11 bytes and in the exact order as defined. > "Beard, Frank" wrote in message > news:... > > One other thing you might want to consider: > > > > > > procedure Write_ABCD (the_Command : Command) is > > > > > > begin > > > > POSIX.IO.write (File_Descriptor, Buffer, Length); > > > > end Write_ABCD; > > > > > > I've used it on both Windows and a couple of Unix flavors without > > any problems, but we were always communicating between homogenous > > platforms (same hardware, same OS). If you are in a heterogeneous > > environment, you have to use a different method, but you have the > > same problem with Unchecked_Conversion. > > > > I like it because it's fairly straight forward and it doesn't copy > > data like Unchecked_Conversion, which is particularly good when > > dealing with large buffers. > > > > Frank > > > Then you would have to take care of the_Command'Size. The 8-byte > record will give you no problem at all. See my post thread "Size and > Pack". > > package ABCD is > > > > type Command is > > record > > A : Character; > > B : Character; > > C : Integer; > > D : Long_Integer; > > end record; -- total 8 bytes; > > > > ... > > end ABCD; > > > > > > POSIX.IO.write (File_Descriptor, Command, Length); > > > > where > > > > procedure Write > > (File : in File_Descriptor; > > Buffer : in IO_Buffer; > > Last : out POSIX.IO_Count; > > Masked_Signals : in POSIX.Signal_Masking > > := POSIX.RTS_Signals); > > > > I have searched the CLA but do not find any solutions. Can you please > > help? > > > > Thank you.