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
306
votes
17 answers

How do I check OS with a preprocessor directive?

I need my code to do different things based on the operating system on which it gets compiled. I'm looking for something like this: #ifdef OSisWindows // do Windows-specific stuff #else // do Unix-specific stuff #endif Is there a way to do this? Is…
perimosocordiae
  • 17,287
  • 14
  • 60
  • 76
214
votes
7 answers

C++ compiling on Windows and Linux: ifdef switch

I want to run some c++ code on Linux and Windows. There are some pieces of code that I want to include only for one operating system and not the other. Is there a standard #ifdef that once can use? Something like: #ifdef LINUX_KEY_WORD ...…
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
153
votes
16 answers

Determining 32 vs 64 bit in C++

I'm looking for a way to reliably determine whether C++ code is being compiled in 32 vs 64 bit. We've come up with what we think is a reasonable solution using macros, but was curious to know if people could think of cases where this might fail or…
Joe Corkery
  • 2,564
  • 3
  • 18
  • 26
148
votes
3 answers

What is the difference between Release and Debug modes in Visual Studio?

Possible Duplicate: Debug vs. release in .NET Debug/Release difference What is the difference between Release and Debug modes in Visual Studio while building a project?
Cute
  • 13,643
  • 36
  • 96
  • 112
113
votes
8 answers

#ifdef #ifndef in Java

I doubt if there is a way to make compile-time conditions in Java like #ifdef #ifndef in C++. My problem is that have an algorithm written in Java, and I have different running time improves to that algorithm. So I want to measure how much time I…
jutky
  • 3,895
  • 6
  • 31
  • 45
96
votes
5 answers

Boolean in ifdef: is "#ifdef A && B" the same as "#if defined(A) && defined(B)"?

In C++, is this: #ifdef A && B the same as: #if defined(A) && defined(B) ? I was thinking it wasn't, but I haven't been able to find a difference with my compiler (VS2005).
criddell
  • 14,289
  • 9
  • 41
  • 45
76
votes
8 answers

C# !Conditional attribute?

Does C# have a not Conditional (!Conditional, NotConditional, Conditional(!)) attribute? i know C# has a Conditional attribute: [Conditional("ShowDebugString")] public static void ShowDebugString(string s) { ... } which is equivalent1…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
71
votes
3 answers

Why does the C# compiler remove a chain of method calls when the last one is conditional?

Consider the following classes: public class A { public B GetB() { Console.WriteLine("GetB"); return new B(); } } public class B { [System.Diagnostics.Conditional("DEBUG")] public void Hello() { …
Kyrio
  • 613
  • 5
  • 11
67
votes
3 answers

What #defines are set up by Xcode when compiling for iPhone

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK.... Presumably Xcode defines something, but I can't see anything under project properties, and Google isn't…
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
57
votes
9 answers

Java conditional compilation: how to prevent code chunks from being compiled?

My project requires Java 1.6 for compilation and running. Now I have a requirement to make it working with Java 1.5 (from the marketing side). I want to replace method body (return type and arguments remain the same) to make it compiling with Java…
khachik
  • 28,112
  • 9
  • 59
  • 94
48
votes
3 answers

Is it possible to define {$IFDEF} for more than one directive at once?

Is it possible to define more than one conditional in one {$IFDEF} directive ? I would like to have syntax like this: {$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF} {$IFDEF Condition1 AND Condition2} DoSomethingElse; {$ENDIF} Thanks
Martin Reiner
  • 2,167
  • 2
  • 20
  • 34
45
votes
5 answers

Which conditional compile to use to switch between Mac and iPhone specific code?

I am working on a project that includes a Mac application and an iPad application that share code. How can I use conditional compile switches to exclude Mac-specific code from the iPhone project and vice-versa? I've noticed that TARGET_OS_IPHONE…
Jose Ibanez
  • 3,325
  • 3
  • 28
  • 33
43
votes
2 answers

What's the difference between #if and #ifdef Objective-C preprocessor macro?

How to define preprocessor macros in build settings, like IPAD_BUILD, and IPHONE_BUILD (and how to use them in my factory methods)? I'm using these by heart now, would be cool to know what is going behind.
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
42
votes
4 answers

c++ #ifdef Mac OS X question

I am fairly new to C++. I am currently working on a group project and we want to make our classes compatible with both the lab computers (Windows) and my computer (Mac OS X). Here is what we have been putting at the top of our files: #ifdef…
Kirsty
  • 421
  • 1
  • 4
  • 3
40
votes
6 answers

Is there anyway to #define CONSTANT on a solution basis?

Is There anyway to #define Constant on a Visual Studio Solution Basis? One can define a constant on a csproject basis, and one can put #define constant in cs file, but I wonder whether one can define it on a vs sln basis?
Graviton
  • 81,782
  • 146
  • 424
  • 602
1
2 3
48 49