Why should #ifdef be avoided in .c files?

Hard to maintain. Better use interfaces to abstract platform specific code than abusing conditional compilation by scattering #ifdefs all over your implementation. E.g. void foo() { #ifdef WIN32 // do Windows stuff #else // do Posix stuff #endif // do general stuff } Is not nice. Instead have files foo_w32.c and foo_psx.c with foo_w32.c: void … Read more

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

You can actually use a variation on Ritch’s approach with common project settings. Essentially you have to make a single change to the end of each project file in your solution: <PropertyGroup Condition=”‘$(SolutionDir)’ == ” or ‘$(SolutionDir)’ == ‘*undefined*'”> <SolutionDir>..\..\</SolutionDir> </PropertyGroup> <Import Project=”$(SolutionDir)CommonSettings.targets” /> </Project> Then you can define CommonSettings.targets to contain the solution wide … Read more

c++ #ifdef Mac OS X question

According to this answer: #ifdef __APPLE__ #include “TargetConditionals.h” #ifdef TARGET_OS_IPHONE // iOS #elif TARGET_IPHONE_SIMULATOR // iOS Simulator #elif TARGET_OS_MAC // Other kinds of Mac OS #else // Unsupported platform #endif #endif So in short: #ifdef __APPLE__ #include “TargetConditionals.h” #ifdef TARGET_OS_MAC #include <GLUT/glut.h> #include <OpenGL/OpenGL.h> #endif #elif defined _WIN32 || defined _WIN64 #include <GL\glut.h> #endif

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

/#if works as usual if: #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { return YES; } #endif return NO; } /#ifdef means “if defined – some value or macros”: #ifdef RKL_APPEND_TO_ICU_FUNCTIONS #define RKL_ICU_FUNCTION_APPEND(x) _RKL_CONCAT(x, RKL_APPEND_TO_ICU_FUNCTIONS) #else // RKL_APPEND_TO_ICU_FUNCTIONS #define RKL_ICU_FUNCTION_APPEND(x) x #endif // RKL_APPEND_TO_ICU_FUNCTIONS or: #ifdef __OBJC__ #import <Foundation/Foundation.h> #endif Use this link for … 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

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

Nope there isn’t any support for conditional compilation in Java. The usual plan is to hide the OS specific bits of your app behind an Interface and then detect the OS type at runtime and load the implementation using Class.forName(String). In your case there no reason why you can’t compile the both OS* (and infact … Read more

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

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

It comes down to the phrase: (including evaluation of the receiver and parameters of the call) is omitted. In the expression: a.GetB().Hello(); the “evaluation of the receiver” is: a.GetB(). So: that is omitted as per the specification, and is a useful trick allowing [Conditional] to avoid overhead for things that aren’t used. When you put … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)