Closed marckleinebudde closed 1 month ago
OMG! This looks like a really weird hack to silence the (false?) warning!!
So why is uint8_t _msg_head[sizeof(struct bcm_msg_head)];
not variable sized anymore?
Shouldn't we better disable the GNU extension -Wgnu-variable-sized-type-not-at-end
instead?
sizeof(struct bcm_msg_head)
is not variable. The sizeof()
is constant, i.e. without any struct can_frame
at the end. Another option is to dynamically allocate it with struct_size()
. It doesn't look that ugly.
What about allocating the memory on the heap instead?
Any objections on the malloc()
approach?
Yes. I would like to avoid malloc() in can-utils where possible. From my understanding we provide software for embedded systems - and therefore malloc() should be avoided.
My preferred idea would still be to disable the -Wgnu-variable-sized-type-not-at-end warning :-/
Btw. what would you think about this approach? https://github.com/hartkopp/can-utils/commit/47e238ae88fd43398df4e93f651095e2a8f5dd51
Btw. what would you think about this approach? hartkopp@47e238a
It doesn't fix the warning.
sigh! - gcc complains about unknown pragma
[ 85%] Building C object CMakeFiles/bcmserver.dir/bcmserver.c.o
/home/bcmserver.c: In function 'main':
/home/bcmserver.c:159:32: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
159 | #pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
closes: https://github.com/linux-can/can-utils/issues/516