• 读《高质量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;
    };
  • 相关阅读:
    深度优先搜索查找图中的所有连通分量
    广度优先搜索BFS-图
    深度优先搜索DFS-图
    稀疏向量算法
    zip函数
    函数(三)>>内置函数
    函数(二)
    面向对象1
    面向对象2
    函数(上)
  • 原文地址:https://www.cnblogs.com/CHENYO/p/2664581.html
Copyright © 2020-2023  润新知