Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: xurei on October 08, 2006, 11:44:51 am

Title: Defines : how to use ?
Post by: xurei on October 08, 2006, 11:44:51 am
Hi there !

I'm using Code::Blocks since few years and I like it ! But there is an option that I cannot use, and I don't know what is wrong in my use... #defines.

Look : I create a target named "debug", with DEBUG 1 in the #defines tab. Then, I write :
Code
int main()
{
#ifdef DEBUG
cout << "debug" << endl;
#endif
/* ... */

return 0;
}

It should show "debug" in the console, but it doesn't... What's wrong ?

Thank you !

PS : I'm using GNU GCC compiler...
Title: Re: Defines : how to use ?
Post by: xurei on October 08, 2006, 01:22:15 pm
A lot of reads, but no answer.... Is it so complicated ? :P
Title: Re: Defines : how to use ?
Post by: stahta01 on October 08, 2006, 01:47:14 pm
It looks like it should work to me.

I would try using a define other than DEBUG; the standard is NDEBUG to say not debug.
and then to test for #ifndef NDEBUG

I am a C::B newbie, so there could be something C::B related that I don't understand.

Tim S
Title: Re: Defines : how to use ?
Post by: xurei on October 08, 2006, 01:57:44 pm
I tried this :
Code
#ifndef ZAFDSGERGEG 
cout << "debug" << endl;
#endif
with ZAFDSGERGEG defined....
And it showed "debug" : it shouldn't :x

I really don't understand :?
Title: Re: Defines : how to use ?
Post by: stahta01 on October 08, 2006, 02:00:58 pm
Where are you defining it?
Title: Re: Defines : how to use ?
Post by: stahta01 on October 08, 2006, 02:03:11 pm
The standard location in CB is
Project -> Build Option
Compiler Tab; #defines Tab
Title: Re: Defines : how to use ?
Post by: MortenMacFly on October 08, 2006, 02:17:20 pm
In the defines tab you have to put DEBUG=1. Notice no spaces and the equality sign.
Edit: Anyway, I tried and it should also work with only having "DEBUG" in the defiens tab.
Did you...
- put the define in a wrong target (e..g in the release target but compiled the debug target?!)
- forget to re-compile after you had changed the define?
- do you set DEBUG=0 somewhere in the code that gets included?
With regards, Morten.
Title: Re: Defines : how to use ?
Post by: MortenMacFly on October 08, 2006, 02:19:27 pm
I tried this :
Code
#ifndef ZAFDSGERGEG 
cout << "debug" << endl;
#endif
with ZAFDSGERGEG defined....
And it showed "debug" : it shouldn't :x
Works very well for me. Did you forget to re-compile?
With regards, Morten.
Title: Re: Defines : how to use ?
Post by: xurei on October 08, 2006, 03:19:10 pm
Okay, here's my real code :
Code
/* debug.h */
#ifdef ZAFDSGERGEG
#include <iostream>
using namespace std;
#define echo(text) cout << text
#else
#define echo(text)
#endif
This code is helpful to show somemore informations when I'm debugging my sources...

And for your questions :
Quote
Did you...
- put the define in a wrong target (e..g in the release target but compiled the debug target?!) NO
- forget to re-compile after you had changed the define? NO (maybe yes actually, but I just recompile completely and the problem is still present...)
- set DEBUG=0 somewhere in the code that gets included? NO

It is not the first time I tried to use the defines, but it never worked...
Title: Re: Defines : how to use ?
Post by: xurei on October 10, 2006, 08:12:55 pm
Ok, I reinstalled C::B, and now it works...
Thank you for the help !
xurei