C/C++ 常用预处理指令

#define, #undef

举例:

/* 定义常量 */
#define ARRAY_SIZE (512)
/* 定义函数宏 */
#define min(a,b) ((a)<(b)? (a):(b))

/* 头文件只包含一次 */
#ifndef MYHEADER_H
#define MYHEADER_H
/* The body of the header file */
#endif /* MYHEADER_H */

/* 取消宏 */
#ifdef MYCOUNT
#undef MYCOUNT

#error ,#warning

说明:#error产生错误消息于处理器终止。#warninig产生一条警告消息,预处理不停止。

举例:

#ifndef __unix__
#error "This section will only work on UNIX systems"
#endif

#warning "this is a warninig"

#if, #elif, #else, #endif

举例:

#if defined(MINXP)
#endif

#if !defined(MINXP)
#endif

#if !(LIMXP > 12)
#endif

#ifdef MINXP
#endif

#ifndef MINXP
#endif

#if MINTXT <= 5
#define MINTLOG 11
#elif MINTXT == 6
#define MINTLOG 12
#elif MINTXT == 7
#define MINTLOG 13
#else
#define MINTLOG 14
#endif

#,##,__VA_ARGS__

/* #宏参数字符串化  */
#define SQRT(ARGTERM) printf("the term " #ARGTERM " is a string\n")
SQRT(far);  /* printf("the term far is a string\n") */

/* ## 两个字符串组合成一个  */
#define MONCK(a) x##a
MONCK(far);  /* xfar */


/* ##__VA_ARGS__  <span style="color: rgb(255, 102, 0); font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错</span>*/
#define errout(a,b,...) \
fprintf(stderr,"File %s Line %d\n",a,b); \
fprintf(stderr,##__VA_ARGS__)




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值