Discussion:
What are these functions (warning, push, disable) are in the macro definition?
(too old to reply)
fl
2017-04-05 14:49:02 UTC
Permalink
Raw Message
Hi,

I have a MSVC project which has the following definitions. It builds
successfully on MSVC, but I don't understand what warning, push, pop
and disable are.

Could you tell me that?

Thanks,


.........................
#if DSAS_MSVC
#define DSAS_MULTILINE_MACRO_END \
__pragma( warning( push ) ) \
__pragma( warning( disable:4127 ) ) \
} \
while( 0 ) \
__pragma( warning( pop ) )
#else /* #if DSAS_MSVC */
#define DSAS_MULTILINE_MACRO_END \
} \
while ( 0 )
#endif
Scott Lurndal
2017-04-05 15:25:14 UTC
Permalink
Raw Message
Post by fl
Hi,
I have a MSVC project which has the following definitions. It builds
successfully on MSVC, but I don't understand what warning, push, pop
and disable are.
Could you tell me that?
Thanks,
.........................
#if DSAS_MSVC
#define DSAS_MULTILINE_MACRO_END \
__pragma( warning( push ) ) \
Push the current warning state on an internal compiler stack.
Post by fl
__pragma( warning( disable:4127 ) ) \
Disable warning 4127, whatever that is
Post by fl
} \
while( 0 ) \
__pragma( warning( pop ) )
Restore the pushed warning state.
Post by fl
#else /* #if DSAS_MSVC */
#define DSAS_MULTILINE_MACRO_END \
} \
while ( 0 )
#endif
Keith Thompson
2017-04-05 20:46:01 UTC
Permalink
Raw Message
Post by fl
I have a MSVC project which has the following definitions. It builds
successfully on MSVC, but I don't understand what warning, push, pop
and disable are.
[...]
Post by fl
.........................
#if DSAS_MSVC
#define DSAS_MULTILINE_MACRO_END \
__pragma( warning( push ) ) \
__pragma( warning( disable:4127 ) ) \
} \
while( 0 ) \
__pragma( warning( pop ) )
#else /* #if DSAS_MSVC */
#define DSAS_MULTILINE_MACRO_END \
} \
while ( 0 )
#endif
This is a non-standard feature of MSVC, documented here:

https://msdn.microsoft.com/en-us/library/2c8f766e.aspx
--
Keith Thompson (The_Other_Keith) kst-***@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Ken Brody
2017-04-06 15:38:38 UTC
Permalink
Raw Message
Post by fl
Hi,
I have a MSVC project which has the following definitions. It builds
successfully on MSVC, but I don't understand what warning, push, pop
and disable are.
Could you tell me that?
Thanks,
.........................
#if DSAS_MSVC
#define DSAS_MULTILINE_MACRO_END \
__pragma( warning( push ) ) \
__pragma( warning( disable:4127 ) ) \
} \
while( 0 ) \
__pragma( warning( pop ) )
#else /* #if DSAS_MSVC */
#define DSAS_MULTILINE_MACRO_END \
} \
while ( 0 )
#endif
First, all pragma statements (except for those starting with "STDC") are
implementation-defined, so you would have to check with a Microsoft-related
group for full details.

However, since I work in MSVC, I recognize it as a basic "temporarily
disable warning number 4127, and then restore it to whatever state it was
before". (That's the "push" and "pop" part.) Apparently, the actual
contents of the macro will generate that warning, and the author wants to
tell the compiler "yes, I know, but it's all good, so shut up about it already".

You can check in a Microsoft-related group, or the MSVC docs for information
on what, exactly, is warning number 4127. Or, a quick web search for "msvc
warning 4127" will answer it as well.
--
Kenneth Brody
Loading...