debug/release module detection

I have a module that writes some diag info to the console. I want to remove the entire module in the release version. This works in VSC, which includes the module. But when I export it for release, this breaks. I think this is supposed to work. I could put the debug annotation at the method level, but I think it should work at the module level too right? Is my syntax wrong?

if ($ has :LogWrites) { LogWrites.writeLog(); }

==================

(:debug)

module LogWrites {

   function writeLog() { ... }
}

Top Replies

  • But when I export it for release, this breaks

    It would've really helped if you had explained exactly how it breaks (i.e. by pasting the error message that you see), rather than expecting…

All Replies

  • But when I export it for release, this breaks

    It would've really helped if you had explained exactly how it breaks (i.e. by pasting the error message that you see), rather than expecting people to guess or to try it themselves. 

    It's almost like you expect people to do a bunch of extra work to try to help you.

    For the benefit of anyone else reading along, building something like this code in release mode results in the following error:

    ERROR: [device name]: [source file]: Undefined symbol ':writeLog' detected.

    What's happening here is that in the code LogWrites.writeLog(), there are symbols that are referenced:

    - LogWrites

    - writeLog

    Since - presumably - neither of these symbols appear in the CIQ API or in other parts of your program, they are undefined for the release build.

    The $ has :LogWrites check only takes care of the undefined LogWrites symbol. (Without that check, you would ofc get a compile-time error about LogWrites being undefined.)

    The compiler is not smart enough to know that if LogWrites is defined (and available on $), then writeLog will also be defined (and available on LogWrites). When you build in release mode, it's as if all the code annotated with :debug simply does not exist.

    That explains the error about writeLog being an undefined symbol. To take care of this error, you could add a 2nd has check like so:

    if ($ has :LogWrites && LogWrites has :writeLog) { LogWrites.writeLog(); }

    But maybe this will look kind of messy. And it may also waste memory for code, especially if you do a lot of logging.

    An alternate solution could look like this:

    (:debug)
    module LogWrites {
       function writeLog() { /* do stuff... */}
    }
    
    (:release)
    module LogWrites {
       function writeLog() { /* do nothing */}
    }
    

  • Thanks!! Much better. With the (:release) annotation I don't even need a "has" test.

    As I presumed, those skilled in the art of MonkeyC quickly understood the context and error without loquacious pontification.