Posted on 2011-03-21
Last Modified: 2012-05-11
#ifdef TEST
            // Line 1
           // Line 1

What if I need multiple lines. is it possible
Question by:learningunix
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Accepted Solution

käµfm³d   👽 earned 250 total points
ID: 35184506
Yes. Everything between the #ifdef and the #endif will be treated as one unit. It is much like a regular "if" statement, but you can think of the #endif as being a substitute for the curly braces.
LVL 16

Expert Comment

ID: 35184509
Yup. You can have as many lines as you like. That why the #else and the #endif are there. They are used to mark the end of the conditional code. In fact, internally, C and C++ don't even "see" lines. It's just one long string of characters. To the parser, newlines, which define the end of lines, are just characters to be ignored like blanks.
LVL 86

Expert Comment

ID: 35184513
Absolutely - actually, that's quite common. Most header files are secured via header guards (, so that's not only more than one line, but merely a whole file.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35185640
Ok. I thought I have to use { } for multiple lines but that is not the case

This should work

#ifdef TEST
            int a = 1;
           printf ("%d"a);            
           // Line 1
           // Line 2

LVL 86

Expert Comment

ID: 35186117
That should definitely work. Just keep in mind that e.g. a #define statement spanning multiple lines needs a trailing backslash if you want to do something like this.
LVL 34

Expert Comment

ID: 35187657
you sometimes will see in code

#if  1
   // some code


the 1 means true and it is easily changed to #if 0 if the code shouldn't be performed anymore. using constants instead of preprocessor macros has advantages for temporary code and code limited to one source cause you don't need to define/undefine a macro like TEST..


Author Closing Comment

ID: 35227103

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question