Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a warning within a C++ macro

In Visual C++ you can temporarily disable a warning by using pragma:

#pragma warning(suppress: 4307)

How can I disable a warning within a macro, e.g., when I cause an "integral constant overflow" warning like this:

#define TIMES_A_MILLION(x) x * 1000000
int value = TIMES_A_MILLION(4711);

I don't want to repeat the warning at every place where the macro is used, but want the suppression to be part of the macro it self.

It is obviously not possible to do like this:

#define TIMES_A_MILLION(x) \
#pragma warning(suppress: 4307) \
  x * 1000000
like image 503
Jordfräs Avatar asked Mar 04 '23 17:03

Jordfräs


1 Answers

In your case you have to use the extension __pragma

__pragma

instead of

#pragma
like image 53
darune Avatar answered Mar 22 '23 22:03

darune