Questions tagged [conditional-compilation]

Compilation of certain parts of source code will be included/excluded. This can be often reached by pre processing the source code in some way. Including/Excluding parts of the source may be controlled by pre processor keywords.

Using conditional compilation a compiler is able to produce differences in the executable produced based on parameters that are provided during compilation. This technique is commonly used when these differences are needed to run the software on different platforms, or with different versions of required libraries or hardware. Typically a preprocessor, such as the or , is used to conditionally process source files before they are passed to the compiler.

References

728 questions
13
votes
2 answers

Does '#'-character have to be at the start of a line in the C preprocessor?

I have programmed C for quite a while now. During this time I have learned that it is a common convention to put the "#"-character that comes before preprocessor-directives at column one. Example: #include int main(void) { #ifdef…
wefwefa3
  • 3,872
  • 2
  • 29
  • 51
13
votes
2 answers

Way to determine whether executing in IDE or not?

In C#/VB in Visual Studio 2010, is there way in the code to determine whether the program is currently running in the IDE or not? eg. If ProgramRunningInIDE Then MessageBox.Show exc.Message
CJ7
  • 22,579
  • 65
  • 193
  • 321
12
votes
2 answers

Is it possible to set the python -O (optimize) flag within a script?

I'd like to set the optimize flag (python -O myscript.py) at runtime within a python script based on a command line argument to the script like myscript.py --optimize or myscript --no-debug. I'd like to skip assert statements without iffing all of…
hobs
  • 18,473
  • 10
  • 83
  • 106
12
votes
1 answer

How do I change a function's qualifiers via conditional compilation?

I have a function that is capable of being implemented as a const: #![feature(const_fn)] // My crate would have: const fn very_complicated_logic(a: u8, b: u8) -> u8 { a * b } // The caller would have: const ANSWER: u8 =…
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
12
votes
4 answers

Conditionally Remove Java Methods at Compile-Time

I am trying to achieve something similar to the C# preprocessor. I am aware that Java does NOT have the same preprocessor capabilities, and am aware that there are ways to achieve similar results using design patterns such as Factory. However, I am…
12
votes
5 answers

Delphi {$IFDEF CONSOLE} Problem

I just tried program Project1; {$APPTYPE CONSOLE} uses SysUtils; begin {$IFDEF CONSOLE} beep; {$ENDIF} end. and expected to hear a beep during runtime, but not. The following test works, though: if IsConsole then beep; Why…
12
votes
6 answers

Tools to generate unit dependencies for Delphi

Are there any tools that can generate dependency diagrams for Delphi units taking into account conditional compilation directives. I'd like to emphasize that this should be unit dependency diagram, not class dependency. Also it would be nice to have…
Max
  • 19,654
  • 13
  • 84
  • 122
12
votes
2 answers

CPP extension and multiline literals in Haskell

Is it possible to use CPP extension on Haskell code which contains multiline string literals? Are there other conditional compilation techniques for Haskell? For example, let's take this code: -- If the next line is uncommented, the program does not…
sastanin
  • 40,473
  • 13
  • 103
  • 130
12
votes
3 answers

How does the Conditional attribute work?

I have some helper methods marked with [Conditional("XXX")]. The intent is to make the methods conditionally compile when only the XXX conditional compilation symbol is present. We're using this for debugging and tracing functionality and it works…
DenaliHardtail
  • 27,362
  • 56
  • 154
  • 233
12
votes
1 answer

Is there an #ifdef in Qt to determine if we're building for Android

I have an Android-specific fix in my Qt application, and I want that code to be compiled only when building for Android. Is there an #if or #ifdef that will do that?
sashoalm
  • 75,001
  • 122
  • 434
  • 781
12
votes
2 answers

Conditional compilation with ifndef and || doesn't catch second case

I'm trying to disable automated crash logs reports when one or both of two defines are set: DEBUG for our debug builds and INTERNATIONAL for the international builds. When I try to do that in the #ifndef case, however, I get the warning Extra tokens…
thegrinner
  • 11,546
  • 5
  • 41
  • 64
12
votes
2 answers

Why am I unable to #ifdef stdafx.h?

I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it. #ifdef _WIN32 #include "stdafx.h" #elif _MAC #include "MAC/stdafx.h" #endif You may wonder why I am using stdafx.h in…
kyue
  • 143
  • 3
  • 8
12
votes
3 answers

Is it possible to use conditional compilation symbols in VS build events?

Say for instance I have a Visual Studio project with a configuration called "MyConfig" and I have the compilation symbol MY_CONFIG_SYMBOL defined. Is there a macro or command to see if MY_CONFIG_SYMBOL is defined in the pre/post build events?…
Mike Webb
  • 8,855
  • 18
  • 78
  • 111
11
votes
4 answers

Conditional compilation in CoffeeScript/UglifyJS

Using Coffeescript I need to have a go through a build script anyway to update my .js files, and I have two of them, one for debugging and one for production (one uses Uglify to minimize the files, one does not). So I was thinking that it would be…
Thilo
  • 257,207
  • 101
  • 511
  • 656
11
votes
4 answers

Conditional compilation in C++ based on operating system

I would like to write a cross-platform function in C++ that contains system calls. What conditional compilation flags can I check to determine which operating system the code is being compiled for? I'm interested mostly in Windows and Linux, using…