can-utils icon indicating copy to clipboard operation
can-utils copied to clipboard

bcmserver: work around "variable sized type not at end" warning

Open marckleinebudde opened this issue 1 year ago • 3 comments

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

marckleinebudde avatar May 06 '24 13:05 marckleinebudde

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?

hartkopp avatar May 06 '24 19:05 hartkopp

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 avatar May 06 '24 19:05 marckleinebudde

What about allocating the memory on the heap instead?

marckleinebudde avatar May 13 '24 14:05 marckleinebudde

Any objections on the malloc() approach?

marckleinebudde avatar May 24 '24 06:05 marckleinebudde

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

hartkopp avatar May 25 '24 14:05 hartkopp

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

It doesn't fix the warning.

marckleinebudde avatar May 26 '24 14:05 marckleinebudde

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

marckleinebudde avatar May 28 '24 09:05 marckleinebudde