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
18
votes
3 answers

Conditionally display block of markdown text using knitr

I would like to edit a single rmarkdown (Rmd) document with a list of "problems", each followed by its solution. Each solution may contain the results of the R console, but also some explaining (markdown and LaTeX formatted) text. Besides, I would…
PabloGregori
  • 147
  • 1
  • 11
18
votes
2 answers

How do I write universal Swift code for both iOS and macOS. In cocoa I could use #ifdef, what do I do now?

For our project we always used one source file for both platforms: iOS and macOS (previously OS X). Right now I am migrating to Swift. Unfortunately there is some files which need import Cocoa and on iOS import UIKit previously we did #ifdef…
JackPearse
  • 2,922
  • 23
  • 31
18
votes
4 answers

How to programmatically change conditional compilation properties of a VBA project

I'm currently working on a VBA code generator/injector that adds VBA functionality to Excel workbooks by using the VBA Extensibility. This all works fine. However, the original code that is injected uses conditional compilation, referring to some…
Peter Albert
  • 16,917
  • 5
  • 64
  • 88
18
votes
2 answers

How do I check if one of multiple macros is defined in a single #ifdef?

I have some C++ code, and want to perform an action if the __APPLE__ or __linux macros are defined. If I did it as a normal if conditional, it would be easy using ||: if (something || something) { .. code .. } But as of what I know there is no ||…
beakr
  • 5,709
  • 11
  • 42
  • 66
18
votes
1 answer

What does @cc_on mean in JavaScript?

Sometimes I see @cc_on in JavaScript. What does it mean?
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
17
votes
4 answers

How to compile specific files in objective-c++ and the rest of the project in objective-c

I'm currently busy on a project where I need to use an external accessory to read Mifare 1k tags. The accessory was provided with an SDK, written in (Objective ?)C++ and I followed the instructions provided to set XCode to "Compile sources as:…
17
votes
4 answers

How to define version "and up" ifdefs in Delphi?

I was working on getting Log4D working in Delphi XE4, and was getting some compile errors because it couldn't find Contnrs in the uses clause, unless I moved it outside the ifdef it was defined in. {$IFDEF DELPHI5_UP} Contnrs, {$ENDIF} A little…
Jessica Brown
  • 8,222
  • 7
  • 46
  • 82
17
votes
1 answer

Why {$IFDEF MSWINDOWS} is replaced with {$IF defined(MSWINDOWS)} in Delphi XE5?

In XE5 all conditional compilations such as {$IFDEF MSWINDOWS} are replaced with {$IF defined(MSWINDOWS)} For example System.Diagnostics.pas in XE4 had ... implementation {$IFDEF MSWINDOWS} uses Winapi.Windows; {$ENDIF} {$IFDEF MACOS} uses…
17
votes
2 answers

Why do people use #ifdef for feature flag tests?

People recommend #ifdef for conditional compilation by a wide margin. A search for #ifdef substantiates that its use is pervasive. Yet #ifdef NAME (or equivalently #if defined(NAME) and related #ifndef NAME (and #if !defined(NAME)) have a severe…
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
17
votes
3 answers

How can I conditionally compile code for emscripten?

Working with a codebase which supports building for multiple Operating Systems, it is only sensible, where modifications for Emscripten are required, to integrate them into the same codebase, with the assistance of conditional compilation to let it…
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
16
votes
11 answers

Use #ifdefs and #define to optionally turn a function call into a comment

Is it possible to do something like this #ifdef SOMETHING #define foo // #else #define foo MyFunction #endif The idea is that if SOMETHING is defined, then calls to foo(...) become comments (or something that doesn't get evaluated or compiled),…
Daniel LeCheminant
  • 50,583
  • 16
  • 120
  • 115
15
votes
3 answers

Conditional compilation symbol for a .NET Core class library

I have created a .NET Core R2 class library and have some common code that I use for several different platforms. Some of the code is not valid in the .NET Core platform and so I wish to wrap it around a conditional compilation symbol. I first…
Gene S
  • 2,735
  • 3
  • 25
  • 35
15
votes
7 answers

Alternatives to Conditional Compilation in C#

What is the alternative to having code with conditional compilation in C#? I have a class that has lots of code that is based on # ifdef .. After sometime my code is unreadable. Looking for refactoring techniques to use for better readability and…
Venki
  • 2,129
  • 6
  • 32
  • 54
14
votes
1 answer

Switching trial and pro builds with android apps in Eclipse: how to make it less painful?

I have an application for Android which comes in two forms: a trial version and a paid "pro" version. The two versions coexists in Android Market and have different package names (let's call them com.app.trial and com.app.pro). They share the same…
antonio
  • 375
  • 4
  • 13
14
votes
5 answers

Preprocessor directives across different files in C#

I know that I can use preprocessor directives in C# to enable/disable compilation of some part of code. If I define a directive in the same file, it works fine: #define LINQ_ENABLED using System; using System.Collections.Generic; #if …
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
1 2
3
48 49