Author Topic: Constant definitions for debug, release etc  (Read 7978 times)

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Constant definitions for debug, release etc
« on: April 14, 2011, 11:23:34 am »
Is there any constants defined when a specific build target is chosen? I mean does CB define anything automatically? I'm trying to compile build target specific code like below:

#if defined DEBUG (can be something CB defines)
    do this;
#elif defined RELEASE (same here)
    do that;

I know I can define them manually but I want to use what CB defines if there is any. Thnx...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Constant definitions for debug, release etc
« Reply #1 on: April 14, 2011, 11:42:23 am »
Inside C::B the "$target"-variable contains the name of the active build-target.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Constant definitions for debug, release etc
« Reply #2 on: April 14, 2011, 12:09:15 pm »
I couldn't think of a way to use it, I guess it won't work when injected into the source like '$target'. So how can I make a constant out of it?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Constant definitions for debug, release etc
« Reply #3 on: April 14, 2011, 12:32:53 pm »
I know I can define them manually but I want to use what CB defines if there is any. Thnx...
There are no automatic/automagic defines, you have to add all you defines in project -> build options -> [target] -> compiler -> defines
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Constant definitions for debug, release etc
« Reply #4 on: April 14, 2011, 01:48:13 pm »
I know I can define them manually but I want to use what CB defines if there is any. Thnx...
There are no automatic/automagic defines, you have to add all you defines in project -> build options -> [target] -> compiler -> defines
Well, I'm not looking for magic, that was what I was looking for. ;) One last question, I've searched but couldn't find and specific information about this. How do I define a constant in project -> build options -> [target] -> compiler -> defines?
Is it like
'#define DEBUG 1'
or just
'DEBUG 1'
or how?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Constant definitions for debug, release etc
« Reply #5 on: April 14, 2011, 02:00:01 pm »
either you just define it, aka value doesn't matter :

Code
DEBUG

or you give it a value

Code
DEBUG=1


Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Constant definitions for debug, release etc
« Reply #6 on: April 14, 2011, 02:16:57 pm »
Ok got it. Maybe because I'm a noob but the work u have done with codeblocks still continues to impress me in every detail. ;) Thnx...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Constant definitions for debug, release etc
« Reply #7 on: April 14, 2011, 02:28:36 pm »
fyi : the common convention is in the release build to define NDEBUG, and don't define anything in debug build.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 640
Re: Constant definitions for debug, release etc
« Reply #8 on: April 14, 2011, 03:47:39 pm »
Yup I know, I guess it's because of the 'assert' macro. ;) Thnx anyway.