Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to WRITE compile time warning for user

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.

like image 309
Yousha Aleayoub Avatar asked Aug 05 '12 19:08

Yousha Aleayoub


People also ask

What is compile time warning?

Compile-time warnings can greatly improve the maintainability of your code and reduce the chance that bugs will creep into it. Compile-time warnings differ from compile-time errors; with warnings, your program will still compile and run.

Do compiler warnings matter?

A compiler warning signals a potentially serious problem in your code. The problems listed above are almost always fatal; others may or may not be, but you want compilation to fail even if it turns out to be a false alarm. Investigate each warning, find the root cause, and fix it.

Do warnings slow down compilation?

However, in general, code with lots of warnings is more likely to be sloppy, and therefore more likely to be inefficient and wasteful (and probably buggy to boot). The more warnings you have, the more stuff that needs to be printed, and the longer the compilation runs.


1 Answers

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

like image 117
Rafał Rawicki Avatar answered Oct 13 '22 14:10

Rafał Rawicki