#5 阮一峰的 C 语言教程学习

2021-09-07
  1. https://wangdoc.com/clang/
  2. GitHub, https://github.com/wangdoc/clang-tutorial

目录

  • 1. 简介
    历史,标准,Hello World
  • 2. 基本语法
    基本语法,printf 格式化
  • 3. 变量
  • 4. 运算符
  • 5. 流程控制
  • 6. 数据类型
  • 整型的不同进制表示
  • limits.h 中的极限值
  • 关于布尔型,int, _Bool(C99, int 别名), bool/true/false (stdbool.h)
  • 字面量后缀 (l, ll, u, f)
  • 类型转换
  • 可移植类型 (stdint.h)
  • 7. 指针
  • 8. 函数
  • 9. 数组
  • 10. 字符串
  • 11. 内存管理
  • 12. struct 结构
  • 13. typedef 命令
  • 14. Union 结构
  • 15. Enum 结构
  • 16. 预处理器
  • 17. I/O 函数
  • 18. 文件操作
  • 19. 变量说明符
  • 20. 多文件项目
  • 21. 命令行环境
  • 22. 多字节字符
  • 23. 标准库
  • 23.1. assert.h
  • 23.2. ctype.h
  • 23.3. errno.h
  • 23.4. float.h
  • 23.5. inttypes.h
  • 23.6. iso646.h
  • 23.7. limits.h
  • 23.8. locale.h
  • 23.9. math.h
  • 23.10. signal.h
  • 23.11. stdint.h
  • 23.12. stdlib.h
  • 23.13. stdio.h
  • 23.14. string.h
  • 23.15. time.h
  • 23.16. wchar.h
  • 23.17. wctype.h

关键字

// 数据类型 12
short   int         long    double  float
char    struct      union   enum    typedef
signed  unsigned

// 变量 6
auto    register    extern  const   volatile
static

// 函数 2
void    return

// 控制语句 11
if      else    for     continue    while  do
switch  case    default goto        break

// 其他 1
sizeof

数据类型

  • 整数:short, int, long, long long
  • signed, unsigned
  • 浮点数:float, double
  • 字符:char, char *
#include <stdio.h>

int main(){
    printf("size of int:         %2ld\n", sizeof(int));
    printf("size of short:       %2ld\n", sizeof(short));
    printf("size of long:        %2ld\n", sizeof(long));
    printf("size of long long:   %2ld\n", sizeof(long long));
    printf("size of float:       %2ld\n", sizeof(float));
    printf("size of double:      %2ld\n", sizeof(double));
    printf("size of long double: %2ld\n", sizeof(long double));
    printf("size of char:        %2ld\n", sizeof(char));
}
$ uname -a
Linux dell 5.11.0-34-generic #36-Ubuntu SMP Thu Aug 26 19:22:09 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

$ gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc /tmp/test.c -o /tmp/test && /tmp/test
size of int:          4
size of short:        2
size of long:         8
size of long long:    8
size of float:        4
size of double:       8
size of long double: 16
size of char:         1

#3 广告拦截器太过分了

2021-07-23

《科技爱好者周刊》第 167 期中,阮一峰十分愤慨的说广告拦截器太过分了。

因为他接到读者反馈,有篇文章中间的两段上下语义似乎不能接上,是否有写内容遗漏。然后检查之后发现是被广告拦截器拦截了。

阮一峰从使用非常广泛的规则集 EasyList (AdBlock 默认开启订阅,每 4 小时更新一次) 发现了很多针对他的规则,并从中摘抄了几句特别狠的:

! 拦截脚本 checker.js
ruanyifeng.com/blog/checker.js

! 隐藏指向 t.cn 的链接
ruanyifeng.com##a[href^="http://t.cn/"]

! 隐藏含有"培训"的段落
ruanyifeng.com##p:-abp-contains(培训)

# 曾经出现过,禁用所有 JS 代码:
ruanyifeng.com^$csp=script-src 'none'

我才知道,广告拦截可以做到这么精准的匹配,真心服!
阮一峰检测到用户开启广告拦截之后,就会不显示所有内容,取而代之的是这个提示:

您使用了广告拦截器,导致本站内容无法显示。
请将 www.ruanyifeng.com 加入白名单,解除广告屏蔽后,刷新页面。谢谢。

其他:

  1. 其实除了浏览器的广告拦截插件之外,HTTP 网关/代理、路由器也可以通过预设规则拦截广告。
  2. 我用过的广告拦截插件:AdBlock (getadblock.com),AdBlockPlus (adblockplus.org),uBlockOrigin (gorhill/uBlock)
  3. AdBlock (下载量 296278) 和 AdBlockPlus (下载量 174432) 的渊源:最早是有一个 Adblock 项目,由于 Adblock 停止更新,一位开发者启动了 AdblockPlus 项目,再后来又有公司基于 AdblockPlus 项目创建 AdBlock。

  4. uBlock (下载量 1658) 和 uBlock Origin (下载量 24666) 的渊源:uBlock 的创始人将项目转移给别人维护之后,好像对后来接收捐款的分配不满,自己又开了一个分支 uBlock Origin。

#2 容错、高可用、灾备

2019-11-19

阮一峰的博文(容错,高可用和灾备)中说:

  • 容错:发生故障时,如何让系统继续运行。
    飞机的四个引擎坏了一个还能继续飞行,汽车的四个轮子坏了一个也能将就驾驶。
  • 高可用:系统中断时,如何尽快恢复。
    汽车的备胎,用于快速恢复正常驾驶(允许短暂的业务中断)。
  • 灾备:系统毁灭时,如何抢救数据。
    飞机的弹射装置,保证最核心的“资产” —— 驾驶员能够存活。