linux-can / can-utils

Linux-CAN / SocketCAN user space applications
2.31k stars 698 forks source link

bcmserver: use pragma to silence gnu-variable-sized-type-not-at-end warning #517

Closed marckleinebudde closed 1 month ago

marckleinebudde commented 2 months ago

closes: https://github.com/linux-can/can-utils/issues/516

hartkopp commented 2 months 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?

marckleinebudde commented 2 months ago

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.

marckleinebudde commented 2 months ago

What about allocating the memory on the heap instead?

marckleinebudde commented 1 month ago

Any objections on the malloc() approach?

hartkopp commented 1 month ago

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

marckleinebudde commented 1 month ago

Btw. what would you think about this approach? hartkopp@47e238a

It doesn't fix the warning.

marckleinebudde commented 1 month ago

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"
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~