How to WRITE compile time warning for user

2020-04-04 17:10发布

问题:

I would like to write a Pragma warning in GNU G++ for every user that compile my codes.

How can i do this? I am using GNU G++ compiler.

回答1:

MSVC and newer GCCs support:

#pragma message ( "your warning text here" )

In GCC the other syntax is also commonly used:

#warning "you warning text here"

See also question: Portability of #warning preprocessor directive and GCC documentation