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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Unchecked_Union record inside an other record - trouble Date: Fri, 08 Aug 2014 23:28:13 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: AnnUDmZwVERVUXyHDyOl5A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21582 Date: 2014-08-08T23:28:13+03:00 List-Id: Shark8 wrote: > On 08-Aug-14 14:12, Victor Porton wrote: >> You forgot "with Unchecked_Union". Certainly your code does not work. > > There's no unchecked union on T2, that was T in your example. > >> >> type T(K: Kind) is >> record >> case K is >> when First => I: int; >> when Second => C: char; >> end case; >> end record >> with Unchecked_Union, Convention=>C; >> >> type T2 is >> record >> Z: int; >> Ob: T; >> end record >> with Convention=>C; > > See? GNAT 4.9 produces no warnings for the below program. Which compiler do you use? I suspect it is a bug in your compiler. Or do we speak about different Ada code? -- main.adb with Interfaces.C; use Interfaces.C; procedure Main is type Kind is (First, Second); type T(K: Kind := Kind'Last) is record case K is when First => X: int; when Second => Y: char; end case; end record with Unchecked_Union, Convention=>C; type Container is record Z: int; R: T; end record; function P (C: Container) return char is begin return C.R.Y; end; begin null; end; -- Victor Porton - http://portonvictor.org