Switching off optimization for a specific function in gcc 4.2.2

前端 未结 7 2229
执笔经年
执笔经年 2020-12-16 16:24

Is it possible to switch off optimization of a specific function? A friend of mine has the problem that the gcc optimization makes some (unknown to me) µ-controller-code not

7条回答
  •  孤城傲影
    2020-12-16 16:44

    The answers so far have neglected the key words in the original question, which are "microcontroller code" It is very common when writing such code to with to disable optimizations -- aggressive optimizers will "optimize away" whole statements whose side effect is to drive the controller. This is a different world from application coding. For an application in the usual space of programming, I came here looking for the same info in order to avoid having a routine for Kahan summation (see wikipedia) optimized into nothingness. So let's not assume that a change of optimization level generating different program behavior is automatically a sign of bad code. Somethings can be kludged by using the volatile keyword cleverly, and in some cases one should generate the actual assembly language and inspect it. (I believe this can still be done with the -S switch to gcc). Let's remember that C is intended to be a sort of portable assembler, not a kind of COBOL.

    Dave

提交回复
热议问题