Skip to content

Commit 71f48ac

Browse files
Fix ticker function cast warnings in GCC 9
The callback function is defined to take a (void*) as parameter, but our templates let users use anything that fits inside sizeof(void*) to be passed in. Add pragmas to stop GCC warnings about this, since we already check the size of the type will fit in the allocated space.
1 parent bb3df45 commit 71f48ac

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libraries/Ticker/Ticker.h

+7
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,21 @@ class Ticker
6464
// C-cast serves two purposes:
6565
// static_cast for smaller integer types,
6666
// reinterpret_cast + const_cast for pointer types
67+
#pragma GCC diagnostic push
68+
#pragma GCC diagnostic ignored "-Wcast-function-type"
6769
_attach_s(seconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void *>(arg));
70+
#pragma GCC diagnostic push
6871
}
6972

7073
template<typename TArg>
7174
void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
7275
{
7376
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
77+
// We know now that we can do a CB and pass back a uint32 for the receiver to interpret as they wish. Disable GCC 9 warning about this
78+
#pragma GCC diagnostic push
79+
#pragma GCC diagnostic ignored "-Wcast-function-type"
7480
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void *>(arg));
81+
#pragma GCC diagnostic push
7582
}
7683

7784
void once_scheduled(float seconds, callback_function_t callback)

0 commit comments

Comments
 (0)