Skip to content

Commit e806b89

Browse files
committed
Fixed handling of const objects in Callback class
Before, the following results in a compilation error: const struct Object *obj; void obj_doit(const Object *obj); Callback<void()> cb(obj, obj_doit); This is especially noticable when migrating from the old Thread constructor, which previously _required_ const. Short term fix for all cv qualifiers through a C cast: void *_obj = (void*)obj;
1 parent 48c1d2e commit e806b89

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

hal/api/Callback.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Callback<R(A0, A1, A2, A3, A4)> {
8080
*/
8181
template <typename T>
8282
void attach(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
83-
_obj = static_cast<void*>(obj);
83+
_obj = (void*)obj;
8484
memcpy(&_func, &func, sizeof func);
8585
_thunk = &Callback::_boundthunk<T>;
8686
}
@@ -221,7 +221,7 @@ class Callback<R(A0, A1, A2, A3)> {
221221
*/
222222
template <typename T>
223223
void attach(T *obj, R (*func)(T*, A0, A1, A2, A3)) {
224-
_obj = static_cast<void*>(obj);
224+
_obj = (void*)obj;
225225
memcpy(&_func, &func, sizeof func);
226226
_thunk = &Callback::_boundthunk<T>;
227227
}
@@ -362,7 +362,7 @@ class Callback<R(A0, A1, A2)> {
362362
*/
363363
template <typename T>
364364
void attach(T *obj, R (*func)(T*, A0, A1, A2)) {
365-
_obj = static_cast<void*>(obj);
365+
_obj = (void*)obj;
366366
memcpy(&_func, &func, sizeof func);
367367
_thunk = &Callback::_boundthunk<T>;
368368
}
@@ -503,7 +503,7 @@ class Callback<R(A0, A1)> {
503503
*/
504504
template <typename T>
505505
void attach(T *obj, R (*func)(T*, A0, A1)) {
506-
_obj = static_cast<void*>(obj);
506+
_obj = (void*)obj;
507507
memcpy(&_func, &func, sizeof func);
508508
_thunk = &Callback::_boundthunk<T>;
509509
}
@@ -644,7 +644,7 @@ class Callback<R(A0)> {
644644
*/
645645
template <typename T>
646646
void attach(T *obj, R (*func)(T*, A0)) {
647-
_obj = static_cast<void*>(obj);
647+
_obj = (void*)obj;
648648
memcpy(&_func, &func, sizeof func);
649649
_thunk = &Callback::_boundthunk<T>;
650650
}
@@ -785,7 +785,7 @@ class Callback<R()> {
785785
*/
786786
template <typename T>
787787
void attach(T *obj, R (*func)(T*)) {
788-
_obj = static_cast<void*>(obj);
788+
_obj = (void*)obj;
789789
memcpy(&_func, &func, sizeof func);
790790
_thunk = &Callback::_boundthunk<T>;
791791
}

0 commit comments

Comments
 (0)