How do I prevent my 'unused' global variables being compiled out?

前端 未结 9 1204
攒了一身酷
攒了一身酷 2020-12-10 00:42

I\'m using static initialisation to ease the process of registering some classes with a factory in C++. Unfortunately, I think the compiler is optimising out the \'unused\'

9条回答
  •  清歌不尽
    2020-12-10 01:16

    you could use

    #pragma optimize off
    int globalVar
    #pragma optimize on
    

    but I dunno if that only works in Visual Studio ( http://msdn.microsoft.com/en-us/library/chh3fb0k(VS.80).aspx ).

    You could also tell the compiler to not optimize at all, especially if you're debugging...

提交回复
热议问题