Skip to content

Commit 5f59a32

Browse files
committed
finish rename
1 parent 514c329 commit 5f59a32

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

modules/opaque-structures.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ actually contains. The reason to do that is not to allow a programmer to depend
77
anytime.
88

99
```C
10-
/* Forward declaration in foo.h */
11-
struct foo;
10+
/* Forward declaration in opaque.h */
11+
struct opaque;
1212

1313
void
14-
do_stuff(struct foo *f);
14+
do_stuff(struct opaque *f);
1515
```
1616
1717
The file implementing `do_stuff()` **will cast the opaque structure object to
1818
an 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 */
2828
void
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.
4040
The structure is usable only via a pointer. Thus, the library has to provide
4141
a function to allocate a structure and return the pointer to it
@@ -45,20 +45,20 @@ inside the structure.
4545
This is handy for libraries so they are free to change the layout of structures
4646
without 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

5656
int
5757
main(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

Comments
 (0)