News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Defines : how to use ?

Started by xurei, October 08, 2006, 11:44:51 AM

Previous topic - Next topic

xurei

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

xurei

A lot of reads, but no answer.... Is it so complicated ? :P

stahta01

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
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

xurei

I tried this :
#ifndef ZAFDSGERGEG
cout << "debug" << endl;
#endif

with ZAFDSGERGEG defined....
And it showed "debug" : it shouldn't :x

I really don't understand :?

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

stahta01

The standard location in CB is
Project -> Build Option
Compiler Tab; #defines Tab
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

MortenMacFly

#6
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

MortenMacFly

#7
Quote from: xurei on October 08, 2006, 01:57:44 PM
I tried this :
#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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

xurei

Okay, here's my real 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 :
QuoteDid 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...

xurei

Ok, I reinstalled C::B, and now it works...
Thank you for the help !
xurei