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

It’s in the SDK docs under “Compiling source code conditionally” The relevant definitions are TARGET_OS_IPHONE (and he deprecated TARGET_IPHONE_SIMULATOR), which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write: #include “TargetConditionals.h” but this is no longer necessary on the current (xCode 6/iOS8) toolchain. So, for example, … Read more

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

You’ve made a mistake in your observations. 🙂 TARGET_OS_MAC will be 1 when building a Mac or iPhone application. You’re right, it’s quite useless for this sort of thing. However, TARGET_OS_IPHONE is 0 when building a Mac application. I use TARGET_OS_IPHONE in my headers all the time for this purpose. Like this: #if TARGET_OS_IPHONE // … Read more

Change name of exe depending on conditional compilation symbol

If you load the .csproj file into a text editor, you can control the AssemblyName property: <AssemblyName Condition=”‘$(Configuration)’ == ‘Debug'”>WindowsFormsApplication9.Debug</AssemblyName> <AssemblyName Condition=”‘$(Configuration)’ != ‘Debug'”>WindowsFormsApplication9</AssemblyName> Note though that this does not only change the file name, but the assembly name, which might mean trouble if you have other code referencing the assembly. I never did this … Read more

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

Macros to the rescue! #![cfg_attr(feature = “const-fn”, feature(const_fn))] #[cfg(not(feature = “const-fn”))] macro_rules! maybe_const_fn { ($($tokens:tt)*) => { $($tokens)* }; } #[cfg(feature = “const-fn”)] macro_rules! maybe_const_fn { ($(#[$($meta:meta)*])* $vis:vis $ident:ident $($tokens:tt)*) => { $(#[$($meta)*])* $vis const $ident $($tokens)* }; } maybe_const_fn! { #[allow(unused)] // for demonstration purposes pub fn very_complicated_logic(a: u8, b: u8) -> u8 { … Read more

Conditional Java compilation

You can set up ‘final’ fields and ifs to get the compiler to optimize the compiled byte-codes. … public static final boolean myFinalVar=false; … if (myFinalVar) { do something …. …. } If ‘myFinalVar’ is false when the code is compiled the ‘do something….’ bit will be missed out of the compiled class. If you … Read more

Conditional compilation depending on the framework version in C#

I don’t think there are any predefined ‘preprocessor’ symbols. However you can achieve what you want like this: Create different configurations of your project, one for every version of CLR you want to support. Choose a symbol like VERSION2, VERSION3 etc. per CLR version. In every configuration, define the one symbol associated with it and … Read more

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

Debug and Release are just labels for different solution configurations. You can add others if you want. A project I once worked on had one called “Debug Internal” which was used to turn on the in-house editing features of the application. You can see this if you go to Configuration Manager… (it’s on the Build … Read more