Reputation: 9638
I was trying to create a small define to work around this bug in QITABENT
and I noticed peculiar behavior of the #pragma warning (disable: ...)
statement.
In the following code the define QITABENT
generates warning C4838
static const QITAB qit[] =
{
QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
};
I can easily suppress this warning, this works:
#pragma warning( push )
#pragma warning( disable: 4838 )
static const QITAB qit[] =
{
QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
//{ 0 },
};
return QISearch(this, qit, riid, ppv);
#pragma warning( pop )
Now I wanted to make a define QITABENTEX
which automatically suppresses the warning generated by QITABENT
. But it seems impossible because when I write the following code the warning C4838
is not suppressed.
static const QITAB qit[] =
{
#pragma warning( push )
#pragma warning( disable: 4838 )
QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
#pragma warning( pop )
//{ 0 },
};
How does the compiler interpret this code in such a way that the warning is not suppressed?
This probably has to with when the definition for QITABENT
is fully resolved.
(Note that I'm not really interested in making the above code work, I'm just really curious how its interpreted by the compiler)
Addendum:
Regarding the close vote and clarification: I got into a discussion with someone giving a shotgun/link-only answer, presumably only reading the question halfway through (since the question explained how to use #pragma
in a macro which is not what I'm asking) now that answer got (self) deleted and I got a close vote for being unclear. So let me reiterate my intentions with this question:
define
to suppress this warningThis question is not about how to suppress a warning in VC++ in general
This question is about trying to understand what happens with the three lines of suppression code in the last code sample. Why do they not have effect in that exact position (in an array initialization) but do have effect outside the array initialization? This probably boils down to answering how and when the pragma statements and macross are resolved.
Upvotes: 3
Views: 1236
Reputation: 11311
The initializer list terminates with the closing curly bracket }
, and that is where warning is generated.
Try this:
static const QITAB qit[] =
{
QITABENT(Derived, Base)
#pragma warning( push )
#pragma warning( disable: 4365 )
}
#pragma warning( pop )
;
[edited]
Per Mr.C64
's comment below, corrected the order of parameters in QITABENT(Derived, Base)
.
Upvotes: 6