Interview Questions

How can I implement opaque (abstract) data types in C

C Interview Questions and Answers


(Continued from previous question...)

How can I implement opaque (abstract) data types in C

One good way is for clients to use structure pointers (perhaps additionally hidden behind typedefs) which point to structure types which are not publicly defined. In other words, a client uses structure pointers (and calls functions accepting and returning structure pointers) without knowing anything about what the fields of the structure are. (As long as the details of the structure aren't needed--e.g. as long as the -> and sizeof operators are not used--C is perfectly happy to handle pointers to structures of incomplete type.Only within the source files implementing the abstract data type are complete declarations for the structures actually in scope.

(Continued on next question...)

Other Interview Questions