Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any way to disable compiler optimisation for a specific line of code?

is there any way to disable compiler optimisation for a specific line of code in Visual studio?

like image 369
coder1234567 Avatar asked Jan 17 '11 12:01

coder1234567


People also ask

How do I disable compiler optimization?

Use the command-line option -O0 (-[capital o][zero]) to disable optimization, and -S to get assembly file. Look here to see more gcc command-line options.

How do I disable optimize code in Visual Studio?

In this dialog, open the Build page and select Active (Debug) from the Configuration dropdown list at the top of the dialog. Then, on the same Build page, disable the Optimize code checkbox and click the Advanced button. Click the image to enlarge it.

How do I turn off optimizations in GCC?

The default optimization level for compiling C programs using GCC is -O0. which turns off all optimizations according to GCC documentation. for example: gcc -O0 test.


2 Answers

No.

Only on a function-by-function basis using the optimize pragma:

 #pragma optimize( "[optimization-list]", {on | off} ) 

The optimize pragma must appear outside a function and takes effect at the first function defined after the pragma is seen. The on and off arguments turn options specified in the optimization-list on or off.

usage:

#pragma optimize( "", off ) . . . #pragma optimize( "", on )  
like image 151
Mitch Wheat Avatar answered Oct 07 '22 08:10

Mitch Wheat


You can use this optimize pragma to control this on a function basis

like image 30
Neera Avatar answered Oct 07 '22 10:10

Neera