zoukankan      html  css  js  c++  java
  • 读《高质量C/C++》 预处理

    #编译预处理
    编译预处理器能识别的指令,只在预编译期起作用,不会进入编译阶段。而常用的预编译处理,主要有文件包含,宏定义,条件编译、#error、#pragma以及预定义符号常量
    1、文件包含 #include
    例如:
    #include <stdlib.h> // <> 开发环境提供的库头文件
    #include "myHead.h" // "" 用户自定义头文件,会在当前文件目录寻找
    #include "..\public\common.h"
    2、宏定义 #define
    例如
    #define NULL 0
    #define FREE( m ) do{ \
    if( ( m ) != NULL ){ \
    free( (m) ); \
    ( m ) = NULL; \
    } \
    }while( 0 )
    3、条件编译 
    a、#if...#else...#endif
    例如
    #if 1
    #define NULL 0
    #elif 0
    #define NULL (void*)0
    #endif
    b、#ifdef...#else...#endif
    例如:
    #ifdef __cplusplus
    #define NULL 0
    #else
    #define NULL (void*)0
    #endif
    c、#ifndef 等同于 #if !define 
    d、#undef 取消宏定义
    例如:
    #undef NULL
    4、#error
    5、#pragma
    #pragma pack( puch,8 )   // 对象成员对齐字节数
    #pragma pack( pop )
    #pragma warning( disable:4069 ) // 不产生 C4069 号编译警告
    #pragma comment( lib,"kernel32.lib" );
    #pragma comment( lib,"user32.lib" );
    #pragma comment( lib,"gdi32.lib" );
    例如:
    #pragma pack( push,8 ) // sizeof( worker ) = 12
    #pragma pack( push,1 ) // sizeof( worker ) = 10
    struct worker
    {
    int a;
    int b;
    char c;
    char d;
    };
  • 相关阅读:
    数组(Array)
    js数据类型自动转化规律
    ES6-12.Symbol
    彻底搞懂prototype和__proto__
    API测试利器——Postman(1. 安装和启动)
    全国各城市的代码邮编sql(mysql版)
    SQL执行的顺序
    jQuery $.each用法
    使用maven工具对maven项目进行打包所出现的问题
    关于Notepad++中用正则表达式匹配中文的问题
  • 原文地址:https://www.cnblogs.com/CHENYO/p/2664581.html
Copyright © 2011-2022 走看看