Hacker News new | past | comments | ask | show | jobs | submit login

The compiler should help the programmer optimize instead.

"Warning: dead store detected (file):line clobbered by (file):line. Use keyword volatile to always store or remove (file):line."

This way the optimization is promoted from the resulting binary to the source code, and bugs / typos / etc can be corrected.




Optimizations often deal with inlined code. The code in the inlined function might be fine in the general sense, but once taken in a particular context, there's dead or redundant code because the compiler can deduce values from context. It might even all fold into a constant.

Telling the developers to optimize these would be equivalent to telling them to start inlining their code (or creating variants of every function that might be inlined, to optimize it for the specific context where it will be inlined).


That's a completely unworkable solution.

The above code isn't necessarily code as the programmer wrote it, but the code after it appears after macroexpansion and various optimization passes. If you were writing C++, the code may be templated.


You would get literally millions of such warnings on your average C codebase.


So basically you are saying that in the average C codebase there are millions of landmines waiting to silently fail on you. This is not a ringing endorsement of the language it's more like a ringing indictment instead.


I certainly do not think that each dead store which has been eliminated is a landmine, this is such an extreme position that it isn't even worth considering. In the very rare cases were I needed a store to actually happen I will use inline asm or some form of volatile.


Which coming back to the main subject isn't ISO C, rather a compiler extension.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: