Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation "else"

In AS3 you can pass a constant to the compiler

-define+=CONFIG::DEBUG,true 

And use it for conditional compilation like so:

CONFIG::DEBUG {    trace("This only gets compiled when debug is true."); } 

I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.

Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:

if (CONFIG::DEBUG) {    //debug stuff } else {    //release stuff } 

I also considered doing something like this but it's still not the elegant solution I was hoping for:

-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG 

Thanks in advance :)

like image 790
takteek Avatar asked Apr 29 '10 10:04

takteek


People also ask

What is meant by conditional compilation?

Conditional compilation provides a way of including or omitting selected lines of source code depending on the values of literals specified by the DEFINE directive. In this way, you can create multiple variants of the same program without the need to maintain separate source streams.

Can you use else for Ifdef?

If expression is zero, the opposite happens. You can use ' #else ' with ' #ifdef ' and ' #ifndef ', too.

What is conditional compilation in C++?

Conditional Compilation: Conditional Compilation directives help to compile a specific portion of the program or let us skip compilation of some specific part of the program based on some conditions. In our previous article, we have discussed about two such directives 'ifdef' and 'endif'.

What is #if and #endif in C?

The #if directive, with the #elif, #else, and #endif directives, controls compilation of portions of a source file. If the expression you write (after the #if) has a nonzero value, the line group immediately following the #if directive is kept in the translation unit.


1 Answers

This works fine and will strip out code that won't run:

if (CONFIG::DEBUG) {    //debug stuff } else {    //release stuff } 

BUT this will be evaluated at runtime:

if (!CONFIG::DEBUG) {    //release stuff } else {    //debug stuff } 

mxmlc apparently can only evaluate a literal Boolean, and not any kind of expression, including a simple not.

like image 167
Peter Hall Avatar answered Oct 14 '22 20:10

Peter Hall