下面的代码产生输出“yes defined”、“no defined”和“yes”。为什么?
#define FOOBAR NO
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef YES
NSLog(@"yes defined");
#endif
#ifdef NO
NSLog(@"no defined");
#endif
#if FOOBAR == YES
NSLog(@"yes");
#else
NSLog(@"no");
#endif
// ...
}
YES 和 NO 不是未定义的,objc.h 将它们定义为:
typedef signed char BOOL;
#define YES (BOOL)1
#define NO (BOOL)0