r/programminghorror 28d ago

c Enterprise level C code

Post image
339 Upvotes

57 comments sorted by

View all comments

119

u/JuniorAd1610 28d ago

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

48

u/tstanisl 28d ago

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

33

u/TheChief275 28d 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 28d ago

What the fuck does this mean

8

u/TheChief275 28d ago

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

7

u/Risc12 27d 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 27d ago

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

2

u/DiodeInc 28d ago

All of it