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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7c012dc36e5f0625,start X-Google-Attributes: gid103376,public From: okellogg@my-dejanews.com Subject: pragma Convention C on discriminated record type Date: 1999/04/08 Message-ID: <7ei6dd$4m3$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 463996270 X-Http-Proxy: 1.0 x3.dejanews.com:80 (Squid/1.1.22) for client 195.243.118.226 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Apr 08 12:11:28 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/2.0 (compatible; MSIE 3.01; Windows NT) Date: 1999-04-08T00:00:00+00:00 List-Id: Hi, The LRM doesn't say anything specific about the effect of pragma Convention (C) when applied to a record type with a discriminant. Is it safe to assume that the appended example will work? (It does with GNAT 3.11p and Rational Apex 3.0.0b, but I'm not sure about others.) Thanks -- oliver.kellogg@vs.dasa.de /* file: uni.h */ typedef enum { one, two } discriminant; typedef struct { discriminant _d; union { unsigned a; float b; } u; } uni; extern void set_a_union (uni *); extern void set_b_union (uni *); /* file: uni.c */ #include "uni.h" void set_a_union (uni *var) { var->_d = one; var->u.a = 1; } void set_b_union (uni *var) { var->_d = two; var->u.b = 2.0; } -- file: ada_uni.adb with Interfaces.C, Ada.Text_IO, Ada.Float_Text_IO; use Interfaces.C; procedure Ada_Uni is type Discriminant is (one, two); pragma Convention (C, Discriminant); type Uni_Type (D : Discriminant := one) is record case D is when one => A : Unsigned; when two => B : C_Float; end case; end record; pragma Convention (C, Uni_Type); procedure Set_A_Union (Var : access Uni_Type); pragma Import (C, Set_A_Union); procedure Set_B_Union (Var : access Uni_Type); pragma Import (C, Set_B_Union); Var : aliased Uni_Type; begin Set_A_Union (Var'access); Ada.Text_IO.Put ("after Set_A_Union: "); case Var.D is when one => Ada.Text_IO.Put_Line ("A is " & Unsigned'Image (Var.A)); when others => Ada.Text_IO.Put_Line ("Whoa! error"); end case; Set_B_Union (Var'access); Ada.Text_IO.Put ("after Set_B_Union: "); case Var.D is when two => Ada.Text_IO.Put ("B is "); Ada.Float_Text_IO.Put (Float (Var.B)); Ada.Text_IO.New_Line; when others => Ada.Text_IO.Put_Line ("Whoa! error"); end case; end Ada_Uni; -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own