bipropellant / bipropellant-protocol

defines and implements a low level protocol shared between a few different hoverboard repositories
MIT License
20 stars 17 forks source link

sizeof in paramstat #16

Closed p-h-a-i-l closed 5 years ago

p-h-a-i-l commented 5 years ago

I think we should change char len; // length of value in tag_PARAMSTAT to int. This way we can check, if somebody wants to use a variable which exceeds our size.

My favourite solution would be to throw an error during compilation. At runtime it's hard to alert the user. Maybe intentional crash?

btsimonh commented 5 years ago

255 would not fit in a message?

p-h-a-i-l commented 5 years ago

well, if we use char, you are limited for sure to 255. Also the whole message handling is limited to a smaller payload.

btsimonh commented 5 years ago

maybe a macro around the sizeof() which reports a compile error if the result is > 253 ish? I'm not great at complex #defines :) - and don't know if you can cause such things as part of a structure definition.

p-h-a-i-l commented 5 years ago

All the macros I found were not satisfying and hard to understand.. This is my proposal: https://github.com/bipropellant/hbprotocol/pull/17