Skip to main content
gamedev.net
🔒 Locked

#warning...

Started by Ancient Spirit 8 replies 850+ views
Original Post
Ancient Spirit
Ancient Spirit
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

#ifdef _DEBUG
//print compile time warning about it.
#endif

Thanks in advance.
This world is ruled by big furry CATS!! :)Meow! :)
SiCrane
SiCrane
There is no #warning directive in standard C++. There is an #error directive, however.
Fruny
Fruny
GCC's preprocessor has #warning, but it is an extension, and not a standard directive.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ancient Spirit
Ancient Spirit
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...

This world is ruled by big furry CATS!! :)Meow! :)
jdhardy
jdhardy
Quote:
Original post by Fruny
GCC's preprocessor has #warning, but it is an extension, and not a standard directive.
So does Metroworks, I believe. MSVC has #pragma message(...) that does pretty much the same thing.
Ancient Spirit
Ancient Spirit
For some reason i don't see those messages anywhere when i'm compiling...
This world is ruled by big furry CATS!! :)Meow! :)
moeron
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?
moe.ron
Ancient Spirit
Ancient Spirit
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();}
This world is ruled by big furry CATS!! :)Meow! :)
Ancient Spirit
Ancient Spirit
Apperantly i can see it under VC++ 6.0 :
Sorry my mistake... It just compiled to fast for me to see..........
This world is ruled by big furry CATS!! :)Meow! :)
TomH
TomH
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.