Using opaque types is an acceptable method of hiding a type's structure. But why not use them all the time? What are the benefits and situations that call for transparent types, especially in C?
Asked
Active
Viewed 73 times
2 Answers
2
Opaque types are much more complicated to write and to use, because you have to do everything with functions, even allocation and initialization.
With "transparent" type you can use variables of the type as normal data. E.g if the underlying type is arithmetic, you'd do some computations. Or if it is a struct
, you'd use the members directly.

ybakos
- 8,152
- 7
- 46
- 74

Jens Gustedt
- 76,821
- 6
- 102
- 177
2
Opaque types require you to write up a full API for tasks such as assignment, comparison, formatted I/O, member access, etc., which may or may not be worth the effort.
And, sometimes, using a plain old scalar is the right answer; would you use an opaque type to store an average? A count?

John Bode
- 119,563
- 19
- 122
- 198