Re:Programming Your Own Language in C++
by flamedoge on Monday August 08, 2016 @02:39AM
(#12245829)
union is a max-size-fits-all solution. a better solution is inheritance.
[ Parent
| on HN ]
Which would introduce the overhead of a vtable, which would vary depending on how deep your inheritance goes. I haven't read the article, but I would maybe use an enum if this is just use to parse variable declarations.
Re:Programming Your Own Language in C++
by beached_whale on Sunday August 14, 2016 @09:24PM
(#12288102)
Generally the vtable is not much slower. I believe around the cost of an extra pointer derefence vs the alternative of branching. Also the compiler can sometimes optimize the cost to be the same as a normal call(e.g. final)