Author Topic: Defines : how to use ?  (Read 7846 times)

xurei

  • Guest
Defines : how to use ?
« 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...
« Last Edit: October 08, 2006, 12:30:50 pm by xurei »

xurei

  • Guest
Re: Defines : how to use ?
« Reply #1 on: October 08, 2006, 01:22:15 pm »
A lot of reads, but no answer.... Is it so complicated ? :P

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7670
    • My Best Post
Re: Defines : how to use ?
« Reply #2 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
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

xurei

  • Guest
Re: Defines : how to use ?
« Reply #3 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 :?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7670
    • My Best Post
Re: Defines : how to use ?
« Reply #4 on: October 08, 2006, 02:00:58 pm »
Where are you defining it?
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7670
    • My Best Post
Re: Defines : how to use ?
« Reply #5 on: October 08, 2006, 02:03:11 pm »
The standard location in CB is
Project -> Build Option
Compiler Tab; #defines Tab
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Defines : how to use ?
« Reply #6 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.
« Last Edit: October 08, 2006, 02:25:29 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Defines : how to use ?
« Reply #7 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.
« Last Edit: October 08, 2006, 02:23:35 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

xurei

  • Guest
Re: Defines : how to use ?
« Reply #8 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...

xurei

  • Guest
Re: Defines : how to use ?
« Reply #9 on: October 10, 2006, 08:12:55 pm »
Ok, I reinstalled C::B, and now it works...
Thank you for the help !
xurei