From: sal714@rs710.gsfc.nasa.gov (Stephen A. Leake)
Subject: Re: C++ to Ada95, help please
Date: 23 Mar 1995 18:01:33 GMT
Date: 1995-03-23T18:01:33+00:00 [thread overview]
Message-ID: <SAL714.95Mar23130133@rs710.gsfc.nasa.gov> (raw)
In-Reply-To: skj@rb.icl.co.uk's message of 20 Mar 1995 08:06:46 -0000
In article <3kjd2m$d3t@jerry.rb.icl.co.uk> skj@rb.icl.co.uk (Simon
Johnston) writes:
In article <3kjd2m$d3t@jerry.rb.icl.co.uk> skj@rb.icl.co.uk (Simon
Johnston) writes:
typedef struct _STRUCT_NAME {.....type struct_STRUCT_NAME is
....................................record
int item1;..........................item1 : int;
union { :
int u_item1; :
long u_item2; :
} u_name; :
int item2;..........................item2 : int;
....................................end record;
} STRUCT_NAME;....................type STRUCT_NAME is new struct_STRUCT_NAME;
The Ada (near) equivalent of a C union is a variant record, but you
need a discriminant. I'll assume item1 is used as a discriminant in
the C structure (good C code does include discriminants); that is, the
value of item1 tells you whether to use u_item1 or u_item2. Then the Ada
equivalent is:
type DISCRIMINANTS is (One, Two);
for DISCRIMINANTS use (One => ?, Two => ?);
type struct_STRUCT_NAME (item1 : DISCRIMINANTS) is
record
case item1 is
when One =>
u_item1 : int;
when Two =>
u_item2 : int;
end case;
item2 : int
end record;
If item1 (or item2) is not used in this way, there is no direct Ada
equivalent structure (and the C code is not very good!).
- Stephe
--
Stephen Leake, NASA Goddard Space Flight Center
email: Stephen.Leake@gsfc.nasa.gov
next prev parent reply other threads:[~1995-03-23 18:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-03-20 8:06 C++ to Ada95, help please Simon Johnston
1995-03-21 23:27 ` Kevin F. Quinn
1995-03-22 5:07 ` Vladimir Vukicevic
1995-03-22 1:22 ` Tucker Taft
1995-03-22 11:38 ` Robb Nebbe
1995-03-23 12:28 ` Mike Meier
1995-03-23 18:31 ` Tucker Taft
1995-03-24 21:24 ` Robert Dewar
1995-03-27 14:58 ` Norman H. Cohen
1995-03-23 13:30 ` Robert Dewar
1995-03-23 18:01 ` Stephen A. Leake [this message]
1995-03-24 9:07 ` Vladimir Vukicevic
1995-03-25 10:02 ` Keith Thompson
-- strict thread matches above, loose matches on Subject: below --
1995-03-08 7:54 Simon Johnston
1995-03-08 13:56 ` Robert A Duff
1995-03-09 21:23 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox