Why #pragma optimize(“”, off)

前端 未结 4 1253
走了就别回头了
走了就别回头了 2021-02-04 03:16

I\'m reviewing a C++ MFC project. At the beginning of some of the files there is this line:

#pragma optimize(\"\", off)

I get that this turns o

4条回答
  •  逝去的感伤
    2021-02-04 03:34

    I know this is an old topic, but I would add that there is another reason to use this directive - though not relevant for most application developers.

    When writing device drivers or other low-level code, the optimizer sometimes produces output that does not interact with the hardware correctly.

    For example code that needs to read a memory-mapped register (but not use the value read) to clear an interrupt might be optimized out by the compiler, producing assembly code that does not work.

    This might also illustrate why (as Angew notes) use of this directive should be clearly documented.

提交回复
热议问题