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 22:52:41 +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:21571 Date: 2014-08-08T22:52:41+03:00 List-Id: Adam Beneschan wrote: > On Friday, August 8, 2014 8:36:48 AM UTC-7, Victor Porton wrote: >> I am trying to interface my program with a C library. > >> The below program does not compile: >> main.adb:19:14: unconstrained subtype in component declaration > >> If this does not work, what should I do to interface a union inside a >> struct in a C library? > >> -- main.adb >> >> with Interfaces.C; use Interfaces.C; > >> procedure Main is > >> type Kind is (First, Second); > >> type T(K: Kind) is > > change this to > > type T(K: Kind := Kind'First) is OK, I followed your way, Adam. But it produces a warning with GNAT 4.9 (for the below program): gnatmake -q -c -gnatc -u -P/home/porton/t/default.gpr main.adb --subdirs=check -cargs -g -O0 -gnato -fstack-check -gnatVa main.adb:26:17: warning: component not present in subtype of "T" defined at line 21 main.adb:26:17: warning: "Constraint_Error" will be raised at run time Should I just disable this warning? (BTW, how to disable this warning in GNAT-GPS?) It seems that there will be a "Constraint_Error" and this is really bad. Any other idea/workarounds? -- main.adb with Interfaces.C; use Interfaces.C; procedure Main is type Kind is (First, Second); type T(K: Kind) 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(Kind'First); end record; function P (C: Container) return char is begin return C.R.Y; end; begin null; end; -- Victor Porton - http://portonvictor.org