c语言(预编译)(precompile)

//  main.m

//  1-26课堂笔记

//讲师: 小辉

//笔者: 王学文

//  Created by lanouhn on 15/1/26.

//  Copyright (c) 2015年 lanouhn. All rights reserved.

// 预编译( Precompile),

 

#import <Foundation/Foundation.h>

 

#define A 12

#define SIZE 150

#define ADD(A, B) A + B

#define MAXVALUE(A, B) A > B ? A : B

#define kMAXVALUE(A, B) A > B ? A : B

#define kMAXVALUE1(A, B) (A > B ? A : B)

#define kMAXVALUE2(A, B) ((A) > (B) ? (A) : (B))

#define kMAXVALUE3(A, B) ({int temp1 = (A); int temp2 = {B}; temp1 > temp2 ? temp1 : temp2;})

#define kMAXVALUE4(A, B) ({__typeof__(A) temp1 = (A); __typeof__(B) temp2 = {B}; temp1 > temp2 ? temp1 : temp2;})

#pragma mark - 打印helloWorld

 

int main(int argc, const char * argv[]) {

    //预编译: 提前编译

    

    //程序编译过程

    //1.预编译

    //2.编译成汇编文件

    //3.编译成目标文件

    //4.目标文件和库文件结合成可执行文件

    

    //宏定义,在预编译期间执行

    //定义格式: #define 名字 表达式

    

    int a = 12;

    int b = A;

    printf("%d %d\n", a, b);

    

    //宏定义,只在编译期间替换(不是函数)

    //

 

    printf("%d\n", MAXVALUE(10, 5));

    

    int max = kMAXVALUE2(3, 4 > 5 ? 4 : 5);

    printf("%d\n", max);

    

    int temp = 3;

    int max3 =  kMAXVALUE3(temp++, 2);

    printf("max3 = %d\n", max3);

    printf("temp = %d\n", temp);

    

    

    //c99中的复合语句;

    int i  = ({

        int k = 3;

        int j = 5;

        k > j ? k : j;

    });

    printf("i = %d\n", i);

#warning 这是个测试数据!

    int aaa = 100;

    

    //条件编译

    

    int d = 0;

//1.

#if 1

    d = 100;

#endif

    

//2.

#if 1

    d = 100;

#else

    d = 200;

#endif

 

//3.

#if 0

    d = 100;

#elif 1

    d = 200;

#else

    d = 300;

#endif

    

    

//4.

#ifdef MAXVALUE

    d = 100;

#endif

    

//5.

#ifndef AAA //只执行一次

#define AAA

    d = 100;

#endif

 

//#error 这是个错误

    

    

    

    printf("%d\n", d);

    

    

    

    

    

    return 0;

}

 

转载于:https://www.cnblogs.com/xiaoxuetongxie/p/4256341.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值