LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2006, 06:47 PM   #1
oulevon
Member
 
Registered: Feb 2001
Location: Boston, USA
Distribution: Slackware
Posts: 438

Rep: Reputation: 30
Conditional Compilation


Hello,

I heard that you can conditionally compile something with the #ifdef and #endif. How can I do this. I've looked online but can't find anything. Here's what I'm doing:

Code:
#ifdef DEBUG

        printf("inside DEBUG block\n");

#endif
When I compile this with gcc -DEBUG -o test test.c, the statement is never executed. Am I doing something wrong?


Thanks for any help.
 
Old 02-26-2006, 08:09 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You're close.

You need "-D" (like you had), and the symbol is "DEBUG". So you were off by one "D":

Quote:
gcc -DDEBUG -o test test.c
You might also wish to consider this alternate syntax:
Code:
#if defined(DEBUG)

        printf("inside DEBUG block\n");

#endif
 
Old 02-26-2006, 08:12 PM   #3
oulevon
Member
 
Registered: Feb 2001
Location: Boston, USA
Distribution: Slackware
Posts: 438

Original Poster
Rep: Reputation: 30
Thanks again for your help.
 
Old 02-26-2006, 08:21 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
My pleasure!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CASE conditional la_mafia63 Linux - General 3 07-24-2005 01:02 PM
c compound conditional steve_96 Programming 9 06-04-2005 07:17 PM
conditional replacment with regexps? MadCactus Linux - General 2 10-01-2004 09:19 AM
conditional not evaluating correctly, help adelatorre204 Programming 4 04-11-2004 10:31 AM
OS Conditional Defines kevin.cowley Programming 1 09-24-2003 03:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration