[riot-notifications] [RIOT-OS/RIOT] gnrc tx-sync: add cast for c++ compatibility (#16441)

Marian Buschsieweke notifications at github.com
Tue May 4 18:24:50 CEST 2021

Hmm, I don't really like this.

E.g. consider the following:

int main(void) {
    int *foo = (int *)malloc(sizeof(int));
    *foo = 3;
    return 0;

The code above is undefined behavior under C, as malloc is implicitly declared as `int malloc(size_t)` due to the missing `#include <stdlib.h>`. The implicit conversion from `int` to `void *` would have been caught by the compiler, but due to the explicit cast it no longer is. (Specifically in RIOT this isn't an issue, as the compiler is instructed to warn about implicit function declarations.) This is just one of the diagnostics the C compiler could offer that is turned off when using explicit casts. For that reason, the explicit cast is considered bad style in C. However, C++ enforces this bad style.

Maybe it makes sense to just disable the C++ warning instead. This would be especially useful, as these kind of issues pop up every now and then; disabling the warning would solve this issue once and for all.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210504/8d5e15d1/attachment.htm>

More information about the notifications mailing list