Re:Type-erased generic functions for C: A modest non-proposal
by cherryteastain on Thursday October 03, 2024 @05:00PM
(#41734950)
Tried it out in godbolt, yes you are right that with the above example gc is able to realize that
can be called with only one type (X) and therefore manages to emit the same code in main_main_pc0. It all falls apart when you add a second struct which satisfies Yer [1], which leads the compiler to emit a virtual function table instead. You can see it in the following instructions in the code with a second implementation for Yer added:
[1] https://godbolt.org/z/zTco4ardx
[ Parent
| on HN ]
Re:Type-erased generic functions for C: A modest non-proposal
by randomdata on Thursday October 03, 2024 @05:03PM
(#41734974)
Was it really necessary to try in gc...? We already talked about how it produces different instructions for the different programs. Nice of you to validate what I already said, I suppose, but this doesn't tell any of us anything we didn't already know.
The intent was for you to try it in other implementations to see how they optimize the code.