0
点赞
收藏
分享

微信扫一扫

【C 语言提高、进阶】Day 8

​​https://www.bilibili.com/video/BV1vb411m7JV​​

预处理

预处理、编译、汇编、链接。

  1. #include
  2. #define
  3. #ifdenf … #endif
  4. 一些特殊作用的预定义宏

理论上#include可以包括.c或者.h文件。

#define PI 3.1415
#define TEST(a, b) a*b
TEST(1+1, 2) 1+1*2
#define TEST(a, b)(a)*(b)

void fun()
{
#define A 10 // 定义了宏定义,下面的代码都可以用,类似全局变量
}
void test()
{
int a = A; //ok
// 取消宏定义
#undef A
int a = A; //err
}
#define MAX2(a, b) (a) > (b) ? (a) : (b)
#deinfe MAX3(a, b, c) (a) > (MAX2(b, c)) ? (a) : (MAX(b, c))
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define test 0

int main()
{
#ifdef test
printf("1");
#else
printf("0");
#endif
}
// 1

生成动态库

日志

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
printf("file= %s\nline= %d", __FILE__, __LINE__);
// file= D:\C_project\BV1vb411m7JV\tmp\main.c
// line= 7

}


举报

相关推荐

0 条评论