Sign in to follow this  
badkeeper3410

Question about Preprocessor Directive

Recommended Posts

hello all. I found some source code with Preprocessor Directive "#if" and I did't understand. Like this: #if 0 #ifndef DotProduct #if ASM #pragma warning (disable: 4035) //__declspec( naked ) float __cdecl DotProduct(const vec3_t v1, const vec3_t v2); #pragma warning( default: 4035 ) #else #ifdef WIN32 float __cdecl DotProduct(const vec3_t v1, const vec3_t v2); #else float DotProduct(const vec3_t v1, const vec3_t v2); #endif #endif #endif #endif what is the "#if 0" means? thanks for help :)

Share this post


Link to post
Share on other sites
Think of them like if() statements executed before compilation in order to include or exclude cerain portions of code.

#IF X means if X is defined && X != 0

Here it is indented so it's easier to see what's going on.

It looks like whoever wrote this wanted to disable the code without removig it
or commenting it out for some reason.

#if 0
#ifndef DotProduct
#if ASM
#pragma warning (disable: 4035)
//__declspec( naked )
float __cdecl DotProduct(const vec3_t v1, const vec3_t v2);
#pragma warning( default: 4035 )
#else
#ifdef WIN32
float __cdecl DotProduct(const vec3_t v1, const vec3_t v2);
#else
float DotProduct(const vec3_t v1, const vec3_t v2);
#endif
#endif
#endif
#endif



Share this post


Link to post
Share on other sites
It can be used for debugging purposes. Zero is false so that code won't run. If you did #if 1 then it would. You can use this to comment out a bunch of code that you want commented out for testing purposes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this