user2354422
user2354422

Reputation: 179

Pragma optimize gives errors

I would like to use the pragma optimize in a function called image() that I have created:

#pragma optimize("", off)
image();
#pragma optimize("", on)

Error 2 error C2156: pragma must be outside function C:....\Visual Studio 2010\Projects\ex4\ex4.cpp 1038

Error 4 error C2156: pragma must be outside function C:....\Visual Studio 2010\Projects\ex4\ex4.cpp 1040

I didn't find out how it would be possible to resolve that.

Upvotes: 1

Views: 1469

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110698

Thes #pragmas should be placed around the function definition of image, not when you call it. Also, note that your order of off and on will disable optimizations for image. For example:

#pragma optimize("", off)
void image()
{
  // ...
}
#pragma optimize("", on)

This will disable the default optimizations (according to the /O compiler option) for the duration of image.

Upvotes: 3

Related Questions