objective-c之预定义

时间:2021-06-02 19:48:03
//
//  main.m
//  预定义
//
//  Created by wu jianhua on 16-8-3.
//  Copyright (c) 2016年 wujianhua. All rights reserved.
//

#import <Foundation/Foundation.h>

#define  message_for(a, b) NSLog(@#a " and " #b ": We love you!")

#define tokenpaster(n) NSLog (@"token" #n " = %d", token##n)


#if !defined (MESSAGE)
#define MESSAGE "You wish!"
#endif

//参数化宏
#define MAX(x,y) ((x) > (y) ? (x) : (y))

typedef unsigned char BYTE;
#define TRUE  1
#define FALSE 0


#define DEBUG 0

#if DEBUG == 0
#define DebugLog(...)
#elif DEBUG == 1
#define DebugLog(...) NSLog(__VA_ARGS__)
#endif


//http://www.yiibai.com/objective_c/objective_c_preprocessors.html
int main(int argc, const char * argv[])
{

    
    
    NSLog(@"File :%s ", __FILE__ );
    NSLog(@"Date :%s ", __DATE__ );
    NSLog(@"Time :%s ", __TIME__ );
    NSLog(@"Line :%d ", __LINE__ );
    NSLog(@"ANSI :%d ", __STDC__ );
    
    message_for(Carole, Debra);
    
    int token110=1024;
    
    tokenpaster(110);
    
    NSLog(@"Here is the message: %s", MESSAGE);
    
    NSLog( @"Value of TRUE : %d", TRUE);
    NSLog( @"Value of FALSE : %d ", FALSE);
    
    DebugLog(@"Debug log, our custom addition gets printed during debug only" );
    
    NSLog(@"NSLog gets printed always" );
    
    //类型转换
    int sum = 17, count = 5;
    CGFloat mean;
    
    mean = (CGFloat) sum / count;
    NSLog(@"Value of mean : %f", mean );
          
                                  
    return 0;
}