Detect compilation on Bada OS - preprocessor

I would like to do something similar to #ifdef __linux__, but with the bada SDK. Is there a constant defined by default?
Also, can I detect when I am compiling for the simulator?

You can, by checking the MingW Compiler's keyword, here's an interesting link that would point you in the right spot... so in theory you could have it this way
#ifdef __MINGW32__
/* we're in the simulator target */
#else
/* we're in the native target */
#endif

I use something like :
#ifdef SHP
# define CONFIG_SUPPORT_API_Osp 1 // bada
#endif
I wish there is also a define that tell sdk version or target api too ..

Use :
#ifdef _DEBUG
// Your code
#endif

Related

XCode: Check destination platform with define

Do exist some standard defines, that specify destination platform, e.g. DEST_IOS or DEST_OSX? Or must I add its in project's settings?
I need this for using same library on Mac and iPad.
Yes. Include TargetConditionals.h, and I use the following to make them a bit easier to use:
#import <TargetConditionals.h>
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
#define TARGET_OSX 1
#else
#define TARGET_IOS 1
#endif
(this is in a common project header file).
And then to use the macros:
#if TARGET_OSX
// OSX-specific thing here
#else
// iOS-specific thing here
#endif

Change Image Based on Target

I am trying to change an image for the two different versions of my app. Here is the code that i have tried so far.
- (void)viewDidLoad
{
[super viewDidLoad];
#ifdef LITE_VERSION
setImage:[UIImage imageNamed: #"30 Tap Game Logo Lite.png"];
#endif
}
You will need to configure your targets' Preprocessor Macros. If you select your target in Xcode and select Build Settings, then search for "preprocessor macros" you'll find the setting you need.
In your light version target (and only in that target) you'll need to add a macro like "LITE_VERSION=1". Then when you build the light version target LITE_VERSION will be defined.
You might also consider using #if LITE_VERSION instead of #ifdef LITE_VERSION just in case you ever want to explicitly turn off LITE_VERSION with #define LITE_VERSION=0.
If you're not sure whether or not your preprocessor macros were set up correctly, you can do something like this:
#ifdef LITE_VERSION
#error Light version is defined.
#else
#error Light version is not defined!
#endif
That will cause the preprocessor to generate an error clearly showing whether or not your macro is defined. (It will also stop the build process, so you can't leave that snippet in your code, but it might help you debug your target configurations.)

Operator 'defined' requires an identifier ios

I've below code in my project dlog should print the values in console if isConsoleLogActive is YES.
It gives error like Operator 'defined' requires an identifier
#if defined ([Util isConsoleLogActive])// Operator 'defined' requires an identifier in this line
#define DLog(...) NSLog(__VA_ARGS__)
#define DTrace() NSLog(#"%s", __PRETTY_FUNCTION__)
#else
#define DLog(...) /* */
#define DTrace() /* */
#endif
if I use the same code([Util isConsoleLogActive]) in my .m it works perfectly fine. I face this issue only in #define
What could be the issue. Please give me some idea.
The various commands that start with # are preprocessor directives. These get executed before the compilation phase at build time, before your application actually executes. You should use the preprocessor directives to conditionally include different code in your application based on build configuration. The preprocessor, however, is the wrong way to handle conditional execution on a specific platform at runtime; for that, you want your standard "if...else" logic.
If your goal with that statement is to determine if the given selector exists, try respondsToSelector, instead.
Result of
[Util isConsoleLogActive]
is not known at compile-time. So you can not use it with '#if defined'.

What is the purpose of using #define to define a constant with no value?

What is the purpose of using #define to define a constant with no value?
Such as:
#define TOKEN
You can use it to enable or disable certain code using #ifdef or #ifndef, eg this:
#ifdef TOKEN
printf("token is defined");
#endif
One use for this would be to toggle logging in debug builds. Another would be include guards.
As #Nutomic says, this sort of #define is useful for enabling/disabling certain bits of code. I've seen this used to create compile-time options for a given library:
#ifdef STRICT_PARSING
//...
#endif
#ifdef APPROXIMATE_PARSING
//...
#endif
#ifdef UNICODE //this is especially useful when trying to control Unicode vs ANSI builds
//call Unicode functions here
#else
//call Ansi functions here
#endif
#ifdef USE_STL //another good one, used to activate or deactivate STL-based bits of an API; the function declarations were dependent on USE_STL being defined. A plain-C API was exposed either way, but the STL support was nice too.
std::string MyApi();
#endif

Literal #YES not working in iOS 5 / Xcode 4.4

New Xcode 4.4 is out and it should support literals like
#42
#"String"
#23.0L
#{ #"key" : obj } and
#[obj1, obj2]
and it should also support #YES and #NO, which isn't working when targeting latest iOS 5 (and prior).
After compiling it show the error message:
Unexpected type name 'BOOL': expected expression
I know you can fix it by typing #(YES) and #(NO). But I want to know the reason why it isn't working as expected.
The reason is Apple forgot the parentheses here:
#define YES (BOOL)1
This will be fixed in iOS 6 SDK:
#define YES ((BOOL)1)
In the meantime you must type #(YES).
This is useful for information about literals.
A commenter on this answer also points out:
There is one small thing I'd like to warn about. Literal bools are also not supported
because of this. However, a quick fix that I implemented was adding
this to the beginning of one of my common headers (in an iOS project)
#ifndef __IPHONE_6_0
#if __has_feature(objc_bool)
#undef YES
#undef NO
#define YES __objc_yes
#define NO __objc_no
#endif
#endif
#phix23s answer seems to be more to the point. You should accept that.
This was worth adding from comments:
It should be noted that this needs to be done after the #import . If one puts these #defines in their Prefix.pch, they should make sure to import Foundation earlier in the pch

Resources