From: tmoran@acm.org
Subject: Re: C-style 'union' in Ada?
Date: Mon, 13 Aug 2001 07:34:06 GMT
Date: 2001-08-13T07:34:06+00:00 [thread overview]
Message-ID: <OpLd7.59206$Kd7.33701592@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: 9l7qon$d78$1@nntp9.atl.mindspring.net
>record that I want to hold a pointer to a buffer which is either a String
>or Wide_String, ...
>... In the package I'm designing, I don't care whether it is a
>String or Wide_String, I will just pass it to the file I/O packages
>(stream, in this case). In C, I would:
How *do* you tell which it is? Or do you really truly neither know
nor care? If so, then the pointer itself is the abstraction
level - it's a black box of bits. It could just as well be an
integer, or an array of bytes, whatever.
If you do have a way to tell, can you incorporate that as a
discriminant in a variant record? eg.
type string_desc(Is_Wide : Boolean) is record
length : Interfaces.C.Unsigned_Long;
case Is_Wide is
when True =>
ansi_string : String_Desc;
when False =>
wide_string : Wide_String_Desc;
end case;
end record;
of course
struct
{
...
string_desc file_name;
...
} some_struct;
will in turn need a discriminant to pass along:
type some_struct(Uses_Wide_String : Boolean) is record
...
file_name : string_desc(Is_Wide => Uses_Wide_String);
...
end record;
It's possible that tagged types would be appropriate. An abstract
parent type with primitive procedures declared for those operations
that treat an object of the type as a black box, and abstract
primitives for those operations that *must* be declared separately
depending on the child type being ansi_string or wide_string.
next prev parent reply other threads:[~2001-08-13 7:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-13 6:06 C-style 'union' in Ada? Brian Catlin
2001-08-13 7:34 ` tmoran [this message]
2001-08-14 3:09 ` DuckE
2001-08-14 3:49 ` Brian Catlin
2001-08-14 7:37 ` Martin Dowie
2001-08-14 9:39 ` Ole-Hjalmar Kristensen
2001-08-14 11:49 ` Martin Dowie
2001-08-14 13:38 ` Ted Dennison
2001-08-16 22:35 ` David Brown
2001-08-17 3:14 ` Brian Catlin
2001-08-17 14:44 ` Ted Dennison
2001-08-17 16:38 ` Jeffrey Carter
2001-08-17 18:17 ` Ted Dennison
2001-08-17 18:45 ` Samuel T. Harris
2001-08-17 3:18 ` Variable sizes for record fields (was: C-style 'union' in Ada) Larry Kilgallen
2001-08-17 6:34 ` Variable sizes for record fields David Brown
2001-08-17 10:44 ` Larry Kilgallen
2001-08-17 19:18 ` Warren W. Gay VE3WWG
2001-08-17 21:36 ` Ken Burtch
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox