[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

ifdef

#ifdef TEST
            // Line 1
#else
           // Line 1
#endif

What if I need multiple lines. is it possible
0
learningunix
Asked:
learningunix
1 Solution
 
käµfm³d 👽Commented:
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.
0
 
imladrisCommented:
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.
0
 
jkrCommented:
Absolutely - actually, that's quite common. Most header files are secured via header guards (http://faculty.cs.niu.edu/~mcmahon/CS241/c241man/node90.html), so that's not only more than one line, but merely a whole file.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

This should work

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

0
 
jkrCommented:
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.
0
 
sarabandeCommented:
you sometimes will see in code

#if  1
   // some code

#endif

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..

Sara
0
 
learningunixAuthor Commented:
thx
0

Featured Post

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now