Post a Reply
Replies- page 2
|Oldest Newest Rating|
· December 28, 2015
Understand that I'm not talking about things like whether a GUI is supported or not. If we keep the GUI logic separate from the processing logic, then we should be able to substitute it for something else merely by changing the compilation commands to link a different module in.
Do you think it's faster to convert a size_t returned by strlen to an int? Not only is that non-portable but it will also most likely introduce extra overhead for handling the sign... Have you thought about that?
Tell me, you wrote some drivers, right? Imagine if every program had different drivers, each one for different filesystems, rather than using fopen and friends and they never made any attempt to reuse any code. Would this be efficient? This is an example of adding architecture dependence to C code, right?
No, of course not. Reinventing the wheel for every program would not only introduce unnecessary testing, maintenance and bugs but would also thrash the CPU cache; it's for this reason that your programs share the same standard library code with other programs. Modularity goes hand in hand with portability.
I suppose you might be thinking of cases such as using right shift instead of multiplying by powers of two? Have you ever thought about how easy it would be for our compilers to do that automatically? They do far more complex optimisations, like hoisting calculations to outside of loops and detecting unreachable code, when they determine that it's safe to do so... Is it possible that your compiler doesn't perform such an optimisation because it would be incorrect (and non-portable) to do so?
How do you quantify your optimisations? How do you ensure that you're targeting the most significant bottleneck, when you're performing such non-portable optimisations? If you can't be sure that you're targeting the most significant bottleneck, is it possible that you might be pushing the most significant bottleneck further and further away from being optimal by writing code that's fast but bulky in other areas?
One of the most popular languages of all time.
|Bucky Roberts Administrator|