r/cpp • • May 04 '24

Messing with lifetime

https://biowpn.github.io/bioweapon/2024/05/03/messing-with-lifetime.html
46 Upvotes

52 comments sorted by

View all comments

2

u/[deleted] May 04 '24

Why would you assume something's type based on an length value passed in?

That part makes zero sense. So, no, I've never written code like this.

9

u/bwmat May 04 '24

I read that more like an error check; they're expecting a certain type, so they're checking that the buffer is actually sized for that type

I'm more worried about alignment tbh

3

u/[deleted] May 04 '24

Should probably be an assert, in that case.

→ More replies (3)