Re: Conditional compilation



Herman Gomez wrote:
Hi,

Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time:

#define debug TRUE
#ifdef(debug)
//debugging code
#endif

That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that.
The only solution I've found is having this kind of code in every debug code block:

if ($debug) {
//debugging code
}

But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production.

Does somebody know if there is something like conditional compilation in PHP that I can use?

Regards,
Herman Gomez
Madrid, Spain.

Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following:

#ifdef(debug)
//debugging code
#endif

---and---

if (defined('DEBUG')) {
//debugging code
}

I don't think checking a define is cpu intensive or even measurable. You could "assume" that it's defined as true or false and:

if (DEBUG === true)) {
//debugging code
}

Still, I don't think that even checking $debug is measurable.

-Shawn
.



Relevant Pages

  • Conditional compilation
    ... Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: ... That way I can include/exclude easily all debugging code in the final compiled code. ... The only solution I've found is having this kind of code in every debug code block: ... Does somebody know if there is something like conditional compilation in PHP that I can use? ...
    (php.general)
  • Re: [PHP] Re: Conditional compilation
    ... Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: ... That way I can include/exclude easily all debugging code in the final compiled code. ... The only solution I've found is having this kind of code in every debug code block: ... // Do something common between DEBUG and!DEBUG modes. ...
    (php.general)
  • Re: [PHP] Re: Conditional compilation
    ... all debugging code at compiling time: ... That way I can include/exclude easily all debugging code in the final ... In PHP I have not been able to find anything like that. ... The only solution I've found is having this kind of code in every debug ...
    (php.general)
  • Re: [PHP] Re: Conditional compilation
    ... all debugging code at compiling time: ... That way I can include/exclude easily all debugging code in the final ... In PHP I have not been able to find anything like that. ... The only solution I've found is having this kind of code in every debug ...
    (php.general)
  • Re: Productivity in programming of C++ programmers
    ... >> debugger will hit the breakpoint. ... I think the reason is that I compiled my library parse.lib in debug mode ... In the past, I found that creating a release parse.lib file, then compiling ...
    (comp.lang.cpp)