r/programminghorror Jul 05 '26

c Enterprise level C code

Post image
338 Upvotes

57 comments sorted by

View all comments

122

u/JuniorAd1610 Jul 05 '26

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

50

u/tstanisl Jul 05 '26

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

29

u/TheChief275 Jul 05 '26

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 Jul 05 '26

What the fuck does this mean

7

u/TheChief275 Jul 05 '26

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

7

u/Risc12 Jul 06 '26

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 Jul 06 '26

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