Is your client looking for a programming or design skill that you don't have? Refer a project to us, earn up to $10,000 in referral commission.
Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

How to use #ifdef and #ifndef to check if an identifier has been defined

On Saturday, July 30th 2005 at 04:46 PM
By Andrew Pociu (View Profile)
-----   (Rated 0 with 0 votes)
More C++ Resources
#ifdef, #ifndef and #endif are preprocessor directives which allow us to check wether or not a value has already been defined using the #define directive. This can be useful when you're including files that may already have the same value defined using #define.

Here's an example that defines the value Whidbey only if it wasn't defined before:

#ifndef Whidbey
#define Whidbey

Similarly, what's between #ifdef and #endif is compiled only if #ifdef returns true (and the value was defined before):

#ifdef Whidbey
// Whidbey is already defined

Digg Digg It!     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this Knowledge Base article
Comment Current Comments
by John on Tuesday, October 30th 2007 at 11:08 PM

Here is a question, suppose we have:

#define Whidbey
#ifndef Whidbey

will this code print out or not printout? when writting #define Whidbey without any value or replacement, will this make the compiler consider Whidbey as already defined? or does it mean we have to PLACE A REPLACEMENT value in the #define for whidbey to be considered defined?

thanks in advance

by PeterP on Monday, May 4th 2009 at 07:29 AM

Even if this article is rather old, I'll answer to this question as it has been unanswered yet.

The preprocessor just keeps a table of keywords and replacement values for these keywords.
The proprocessor does not care for empty replacements (which will simply remove the keyword from the proprocessor output).
In the #ifdef directive (as well as #ifndef and #if defined(x) ) simply checks for an existing entry in the table. The line with the directive (and maybe any text between the #if and the #endif) is also removed from the output.
Replacement takes only place outside preprocessor directives or when evaluating an #if expression (but not in the defined() expression)

So the answer to your question is: no, the text won't be printed, as #ifndef Whidbey' evaluates to false (Whidbey is defined), so all three lines are removed from the preprocessor output and the compiler will never see them.

by on Thursday, January 19th 2012 at 06:00 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view

Comment Comment on this Knowledge Base article
Name: Email:
Knowledge Base Related Knowledge Base Articles
There are no related KB articles.

Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C++ Job Search
My skills include:

Enter a City:

Select a State:

Advanced Search >>
Discover Geekpedia