How to check release / debug builds using cfg in Rust?

You can use debug_assertions as the appropriate configuration flag. It works with both #[cfg(…)] attributes and the cfg! macro: #[cfg(debug_assertions)] fn example() { println!(“Debugging enabled”); } #[cfg(not(debug_assertions))] fn example() { println!(“Debugging disabled”); } fn main() { if cfg!(debug_assertions) { println!(“Debugging enabled”); } else { println!(“Debugging disabled”); } #[cfg(debug_assertions)] println!(“Debugging enabled”); #[cfg(not(debug_assertions))] println!(“Debugging disabled”); example(); } … Read more

How do I override a Python import?

Does this answer your question? The second import does the trick. Mod_1.py def test_function(): print “Test Function — Mod 1” Mod_2.py def test_function(): print “Test Function — Mod 2” Test.py #!/usr/bin/python import sys import Mod_1 Mod_1.test_function() del sys.modules[‘Mod_1’] sys.modules[‘Mod_1’] = __import__(‘Mod_2’) import Mod_1 Mod_1.test_function()

Managing highly repetitive code and documentation in Java

For people that absolutely need performance, boxing and unboxing and generified collections and whatnot are big no-no’s. The same problem happens in performance computing where you need the same complex to work both for float and double (say some of the method shown in Goldberd’s “What every computer scientist should know about floating-point numbers“ paper). … Read more

Why include guards?

Simply because you might have wanted the compiler to load that file twice. Remember, that #include simply loads a file and puts its contents in the place of the directive. This file might be a header file, but may be useful and frequently used piece of source code as well. Most modern compilers react to … Read more

Using preprocessor directives in BlackBerry JDE plugin for eclipse?

Within the eclipse config file (%ECLIPSE_HOME%\configuration\config.ini) make sure the following line exists. osgi.framework.extensions=net.rim.eide.preprocessing.hook With the current BlackBerry plugin (1.0.0.67) config line is added for you. I’m not sure about older versions of the plugin. Also, checkout this Stack Overflow question for more information on the BlackBerry preprocessor. Preprocessor directives supported by the RIM compiler

CUDA and nvcc: using the preprocessor to choose between float or double

It seems you might be conflating two things – how to differentiate between the host and device compilation trajectories when nvcc is processing CUDA code, and how to differentiate between CUDA and non-CUDA code. There is a subtle difference between the two. __CUDA_ARCH__ answers the first question, and __CUDACC__ answers the second. Consider the following … Read more

Swift: how to use PREPROCESSOR Flags (like `#if DEBUG`) to implement API keys?

Apple included full support for Swift preprocessor flags as of Xcode 8, so it’s no longer necessary to set these values in “Other Swift Flags”. The new setting is called “Active Compilation Conditions”, which provides top-level support for the Swift equivalent of preprocessor flags. You use it in exactly the same way as you would … Read more