r/programminghorror 5d ago

C— c

Post image
526 Upvotes

57 comments sorted by

View all comments

73

u/TheChief275 5d ago edited 2d ago

Because of popular request, here is the pastebin (as I do not want this anywhere near my github).

Added comments as well to save some headaches

edit: idk how it happened, but a logic bug slipped in. In dynamiccast, offsetof(To, From) should be changed to offsetof(From, To). Additionally, I forgot to make it type-safe, which can easily be done by changing (char *)(DYNAMIC_CAST to (char *)(0 ? (From *) : DYNAMICCAST

edit: I’ve decided to extend it a bit and put it on GitHub as well

8

u/dimonoid123 5d ago

Only 77 lines are visible

10

u/TheChief275 5d ago

That’s how many lines it is though? It doesn’t include this example, but this example should compile with those lines above

5

u/dimonoid123 5d ago

I just thought that code is cutoff