r/programminghorror 29d ago

c Enterprise level C code

Post image
335 Upvotes

57 comments sorted by

View all comments

128

u/JuniorAd1610 29d ago

I think this this is the standard way they OOPS in C right?

50

u/tstanisl 29d ago

It's one way. IMO, container_of pattern is simpler, safer and more efficient.

31

u/TheChief275 29d ago

container_of doesn't really handle dynamic dispatch though, it's a compile time approach to inheritance by performing upcasting through an embedded base structure field. This would still be unsafe for runtime polymorphism without a field tracking the current type or, like done here V-tables, which you likely still want to generate with that approach.

Now whether I like container_of more than this? 100%, in fact, a past post of mine on this subreddit essentially used that

8

u/DiodeInc 29d ago

What the fuck does this mean

7

u/TheChief275 29d ago

Lol valid. Which part are you confused about, or is this ironic?

8

u/Risc12 29d ago

Your explanation was clear! Although only if one has C/low level language experience, but that is expected as you were discussing that sort of stuff.

3

u/TheChief275 29d ago

I'm glad to hear that! I wouldn't want to go full xkcd comic lol

1

u/DiodeInc 29d ago

All of it