What defines an opaque type in C, and when are they necessary and/or useful?

后端 未结 3 2011
你的背包
你的背包 2020-12-05 01:37

I\'ve seen the concept of \'opaque types\' thrown around a bit but I really haven\'t found a succinct answer as to what defines an opaque type in C and more importantly what

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 02:11

    In my understanding, opaque types are those which allow you to hold a handle (i.e., a pointer) to an structure, but not modify or view its contents directly (if you are allowed to at all, you do so through helper functions which understand the internal structure).

    Opaque types are, in part, a way to make C more object-oriented. They allow encapsulation, so that the internal details of a type can change--or be implemented differently in different platforms/situations--without the code that uses it having to change.

提交回复
热议问题