@@ -7,35 +7,35 @@ actually contains. The reason to do that is not to allow a programmer to depend
77anytime.
88
99``` C
10- /* Forward declaration in foo .h */
11- struct foo ;
10+ /* Forward declaration in opaque .h */
11+ struct opaque ;
1212
1313void
14- do_stuff (struct foo * f);
14+ do_stuff (struct opaque * f);
1515```
1616
1717The file implementing `do_stuff()` **will cast the opaque structure object to
1818an internal structure type**.
1919
2020```C
21- /* in foo_impl .h not provided to the consumers */
22- struct foo_impl {
21+ /* in opaque_impl .h not provided to the consumers */
22+ struct opaque_impl {
2323 int x;
2424 int y;
2525};
2626
2727/* library implementation code */
2828void
29- do_stuff(struct foo *f)
29+ do_stuff(struct opaque *f)
3030{
31- struct foo_impl *fi = (struct foo_impl *)f;
31+ struct opaque_impl *fi = (struct opaque_impl *)f;
3232
3333 fi->x = ...
3434 fi->y = ...
3535}
3636```
3737
38- Then any ` .c ` file that includes ` foo .h` can work with the structure
38+ Then any ` .c ` file that includes ` opaque .h` can work with the structure
3939(by passing it to ` do_stuff() ` ) however cannot access its members directly.
4040The structure is usable only via a pointer. Thus, the library has to provide
4141a function to allocate a structure and return the pointer to it
@@ -45,20 +45,20 @@ inside the structure.
4545This is handy for libraries so they are free to change the layout of structures
4646without breaking the consumers.
4747
48- The consumer of the library then ` #include ` s only ` foo .h` but it does not have
49- access to ` foo_impl .h` .
48+ The consumer of the library then ` #include ` s only ` opaque .h` but it does not have
49+ access to ` opaque_impl .h` .
5050
5151``` C
5252#include < stdio.h>
5353
54- #include " foo .h"
54+ #include " opaque .h"
5555
5656int
5757main (void)
5858{
59- struct foo * h;
59+ struct opaque * h;
6060
61- h = getFoo ();
61+ h = getOpaque ();
6262 doStuff(h);
6363}
6464```
0 commit comments