harpiee
Re:My personal C coding style as of late 2023
on Monday October 09, 2023 @09:59AM (#37820514)
Smart pointers for what?
I don't use any dynamically allocated memory in my firmware projects.
I do sometimes use statically allocated pools for things like packet buffers and allocate chunks out of them, but their lifetimes are not scope based, so automatic call of constructors/destructors would not be of any help.
Re:My personal C coding style as of late 2023
on Monday October 09, 2023 @06:09AM (#37818785)
I do it mainly as a form of namespacing and aid in readability.
do_thing(foo); // foo is variable
do_thing(FOO); // FOO is constant (i.e this call should always do the same thing)
foo = FOO; // I wanna name a variable the same as a constant
Re:My personal C coding style as of late 2023
on Monday October 09, 2023 @04:24AM (#37818251)
With unsigned you can actually check for overflow yourself very easily
z=x+y; if(z < x || z < y) // overflow
And bounds checks are just a single comparisons against an upper bound (handles both over and underflow) size = x + y;
// or
size = x - y
if(size < bound) // good to go
Prior to C23 (stdckdint.h) its very error prone to check for signed overflow since you have to rearrange equations to make sure no operation could ever possibly overflow.