5 ms·
An interesting trick, but it seems like there would be a simpler way, like having set_the_mtime be a function pointer. Initially it would point to an implementa
by usefulcat 8y ago
An interesting trick, but it seems like there would be a simpler way, like having set_the_mtime be a function pointer. Initially it would point to an implementation that figures out which method works and sets the function pointer to point to a particular implementation.
- ychen306 8y agoIt's more inliner-friendly this way though.
- megous 8y agoNo. Compiler can't assume value of switch_step at compile time, so it would have to inline the whole horrid thing every single time.
- beefsack 8y agoSounds really clever, but also has the potential to be really opaque and confusing. On the other hand, the trick in the article is quite verbose. Can be tricky balancing terseness with readability.
- Sharlin 8y agoI would say that this switch hack is lightyears more "clever" (that is, opaque and confusing) than a simple function pointer.
- usefulcat 8y ago> has the potential to be really opaque and confusing Yes, but.. compared to switch and preprocessor hacks described in the article? Granted it's subjective but I'd find a function pointer that's assigned to once to be way easier to comprehend.
- carlmr 8y agoYeah, I think both methods are somewhat opaque, and the one described here is opaque + hacky. I wouldn't let this through code review.
- corndoge 8y agono guarantee the signatures are the same on all functions, can't use a fp
- kochthesecond 8y agoHave you heard of our Lord and savior, the single method interface?
- jfries 8y agoIn that case wrapper functions can be created where needed to normalize the signatures.
- bayindirh 8y agoCreating signature normalization wrappers, which contain superset of all the function parameters really complicates the code a lot. It's like trying to push anything and everything through a little hole.