Better HN
topnewbestaskshowjobs
Log inSign up

harpiee

10 karma · joined Oct 9, 2023 (3y ago) · 3 submissions

Submissions

comment 3y ago · link · parent

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.

comment 3y ago · link · parent

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

comment 3y ago · link · parent

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.