From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: gnat -xdr flag confusion. Date: Tue, 4 Jul 2023 13:39:29 +0200 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 4 Jul 2023 11:39:29 -0000 (UTC) Injection-Info: dont-email.me; posting-host="043ae2cbd5e9ab0720db7f7c64418928"; logging-data="35394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183/QEq6xcyGDGgWz7CjgF0mDXD6zGVUhM=" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Cancel-Lock: sha1:PfKyl0STcu7RvHAImsKDYAnaHao= In-Reply-To: Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:65423 List-Id: On 2023-07-04 12:56, magardner2010 wrote: > However, if the ada code encodes the object with 'write, then it creates > something about 4 bytes too short, and if I use 'output, it is parsed as > starting with family_type 256, which is not a member of the enum. Given > that the gnat documentation for the -xdr flag is literally two lines, I > don't really know where to look for more information on what I'm doing > wrong. You never defined the protocol and implemented it in the first place. You used some code generation tools which, if ever worked, will bite you in the end. To summarize the problem. The stream attribute 'Write writes the constrained object. 'Output adds the constraints. Ada is capable to have variable length records. C cannot do this. In short, it means that XDR's discriminated union can be mapped onto Ada's variant record with no default discriminant, but it cannot be directly mapped onto C's union. I presume that GNAT implements XDR correctly and the C side does not cope. Which is one of thousand reasons not to implement a communication protocol by deriving representation from some language objects. Cutting corners will not help you. Define the (application level [*]) protocol. Implement it in Ada. Implement it in C. Done. --------------------- * XDR or ASN.1 or whatever are not application level! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de