In article <. com>,
writes:
> Michael Wojcik wrote:
> > In article < om>, writes:
> > >
> > > If client code should view the type as opaque, then
> > > using typedef for a struct type makes sense.
> >
> > Perhaps, but since C already contains an idiom for opaque types which
> > does not require a typedef, the typedef is still superfluous.
>
> You're using the term opaque in different
> sense than I was.
Perhaps I am, but I find the distinction you draw trivial and
superfluous.
> As I was using the term,
> opaque means a type that client code should
> know nothing about.
This cannot be achieved in C. The "client code" can still apply the
sizeof operator to a typedef, for example. Assuming an implementation
with decent QoI, trial code can be written to determine what types the
typedef is compatible with, by observing diagnostics.
> The "opaque type" that
> you suggest requires client code to know
> (a) that it's a pointer and (b) that the
> pointer points to a struct.
So what? In some languages (eg OCaml), essentially all user-defined
types are references to structured types. That doesn't seem to be a
problem for them. I'll be damned if I can think why this would be a
problem in C. What precious information is leaking out of the abstract
interface?
> That's more translucent than opaque.
The size and nature of the contents are invisible outside the
interface. That's as good a definition of "opaque type" as any other
I've seen.
> A type intended to be really opaque should
> use typedef.
You're welcome to that opinion. I don't find it convincing.
I'll also note in passing that using typedefs for "opaque" (abstract)
types encourages not wrapping elementary types in structs. And that,
in turn, may lead to maintenance problems, if the type needs to be
extended later, but existing callers have divined its non-struct
nature (eg by reading headers) and written code that relies on that
fact.
If struct is your only type-abstraction mechanism, this is never an
issue.
--
Michael Wojcik
He smiled and let his gaze fall to hers, so that her cheek began to
glow. Ecstatically she waited until his mouth slowly neared her own.
She knew only one thing: rdoeniadtrgove niardgoverdgovnrdgog.