You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/api/platform/platform.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ C++ provides the tools to delegate this complexity to a single class. This class
71
71
72
72
<h4 id="the-importance-of-state">The importance of state</h4>
73
73
74
-
Callbacks have two important pieces of information, the code to execute and the state associated with the callback.
74
+
Callbacks may have two important pieces of information, the code to execute and the state associated with the callback.
75
75
76
76
A common API design mistake is to use a callback type that doesn’t allow a user to attach state to a callback. The most common example of this is a simple C function pointer:
77
77
@@ -88,7 +88,7 @@ public:
88
88
};
89
89
```
90
90
91
-
This API is sufficient for simple applications but falls apart when there are multiple ADC modules available. This problem becomes especially noticeable when a user tries to reuse the same procedure for multiple callbacks.
91
+
This API is sufficient for simple applications, but falls apart when there are multiple ADC modules available. This problem becomes especially noticeable when a user tries to reuse the same procedure for multiple callbacks.
92
92
93
93
For example, consider applying a low-pass filter to two different ADC modules
94
94
@@ -111,7 +111,7 @@ int main() {
111
111
}
112
112
```
113
113
114
-
Without state, callbacks offer very limited composability. In C, you can fix this by adding an additional “state” argument to the function pointer, which allows you to pass in the opaque “state” when you register the callback.
114
+
Without state, callbacks compose poorly. In C, you fix this by adding a "state" argument to the function pointer, and by passing opaque "state" when you register the callback.
115
115
116
116
Here’s the low-pass example using an additional argument for state.
117
117
@@ -150,7 +150,7 @@ int main() {
150
150
}
151
151
```
152
152
153
-
One of the core features of C++ is the encapsulation of this “state” in classes, with operations that modify the state being represented as member functions in the class. Unfortunately, member function pointers are not compatible with standard function pointers, but you can rewrite the low-pass example to use member function pointers, allowing you to pass in state as a C++ object. The Callback class fills this void by offering a function pointer like class that is able to use member function pointers.
153
+
One of the core features of C++ is the encapsulation of this "state" in classes, with operations that modify the state being represented as member functions in the class. Member function pointers are not compatible with standard function pointers. The Callback class allows API authors to implement a single interface that accepts a Callback, and the user may provide a C function and state or C++ member function and object without special consideration by the API author.
154
154
155
155
Here’s the low-pass filter example rewritten to use the callback class:
0 commit comments