#ifdef _DEBUG
//print compile time warning about it.
#endif
🔒 Locked
#warning...
Advertisement
Original Post
Hey, is there a #warning directive in C\C++. I want to print compile time warnings, and i tried the #warning but soon i realized the cold and painful truth... it is for C# :P Thanks in advance.
Quote:
Original post by SiCrane
There is no #warning directive in standard C++. There is an #error directive, however.
Yea.. But the thing is that i don't want to stop the compilation process...
Quote:So does Metroworks, I believe. MSVC has #pragma message(...) that does pretty much the same thing.
Original post by Fruny
GCC's preprocessor has #warning, but it is an extension, and not a standard directive.
For some reason i don't see those messages anywhere when i'm compiling...
Quote:
Original post by moeron
are you sure the part of code where you placed the message is being compiled? #pragma message should show up in the same window as all the build logging stuff. What compiler are you using?
Microsoft Visual Studio .NET
#include <stdio.h>// Cheking for OS and including the needed headers for that OS only#if defined(LINUX)#include <curses.h>#elif defined(WIN32)#include <conio.h>#else#error The program needs to know what operating system are you runnig to compile this program: for Linux - LINUX, for Windows - WIN32.#endif//bool type for Ctypedef enum { false, true } bool;unsigned getbits(unsigned x, int p, int n){ return (x >> (p+1-n)) & ~(~0 << n);}void main(){ printf("%d\n", getbits(8, 4, 3));#ifdef _DEBUG#pragma message("Debug mode activated") printf("Program terminated");#endif getch();}
Apperantly i can see it under VC++ 6.0 :
Sorry my mistake... It just compiled to fast for me to see..........
Sorry my mistake... It just compiled to fast for me to see..........
As a neat aside, on VC6 (and probably VC7). If you write a pragma message in the same form as a 'normal' compiler warning it will be included in the final summary of 'n' warnings and 'm' errors.
i.e.
#pragma message("warning: Debug mode activated")
I don't have a compiler to check the format, but I'm sure you get the idea. Obviously this is far more useful if you aim to compile with zero (or a very few) warnings.
Cheers,
Tom
i.e.
#pragma message("warning: Debug mode activated")
I don't have a compiler to check the format, but I'm sure you get the idea. Obviously this is far more useful if you aim to compile with zero (or a very few) warnings.
Cheers,
Tom
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement