From: okellogg@my-dejanews.com
Subject: pragma Convention C on discriminated record type
Date: 1999/04/08
Date: 1999-04-08T00:00:00+00:00 [thread overview]
Message-ID: <7ei6dd$4m3$1@nnrp1.dejanews.com> (raw)
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
reply other threads:[~1999-04-08 0:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox