From f783b00f389581244ecb3bc3d40367f5408cdc2a Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Fri, 23 Aug 2024 12:38:26 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E8=A1=A8=E6=8F=8F=E8=BF=B0=E4=B8=AD`=E7=89=A9=E7=90=86?= =?UTF-8?q?=E5=9C=B0=E5=9D=80`=E4=B8=BA`=E9=80=BB=E8=BE=91=E5=9C=B0?= =?UTF-8?q?=E5=9D=80`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1_\347\272\277\346\200\247\350\241\250.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" index 9bb528d..f5f331e 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" @@ -25,7 +25,7 @@ ### 2.1 基本概念 -1. 物理结构,元素存储在一段 **物理地址连续** 的存储单元上 +1. 物理结构,元素存储在一段 **逻辑地址连续** 的存储单元上 2. 通常使用数组实现 3. 因为数组下标从 **0** 开始,所以 **逻辑下标** 为 **1** 的元素存储在数组下标为 **0** 的位置上,这个下标称为此元素的 **物理下标** 4. 在顺序表中,通常情况下,**物理下标** = **逻辑下标-1** From 47ed2b963ddf1a157692857da35ed3b91156eb35 Mon Sep 17 00:00:00 2001 From: LY-Xiang Date: Fri, 23 Aug 2024 12:47:27 +0800 Subject: [PATCH 2/7] mdlint&&format --- ...345\210\235\350\257\206HAL\345\272\223.md" | 8 +- ...30\345\231\250\347\274\226\347\250\213.md" | 2 +- .../\346\234\257\350\257\255\350\241\250.md" | 17 +- ...57\345\242\203\346\220\255\345\273\272.md" | 37 ++-- ...75\344\270\216\350\260\203\350\257\225.md" | 4 +- ...4_\344\275\215\346\223\215\344\275\234.md" | 15 +- .../\351\241\271\347\233\256/MdrOS/build.md" | 93 +++++---- .../MdrOS/interrupt.md" | 20 +- .../\351\241\271\347\233\256/MdrOS/memory.md" | 9 +- .../MdrOS/video_driver.md" | 18 +- ...71\347\233\256\346\246\202\350\277\260.md" | 10 +- ...63\344\272\216\350\277\233\345\210\266.md" | 10 +- .../linkfix.py" | 9 +- ...\346\240\210_\346\225\260\347\273\204_1.h" | 31 ++- .../\351\241\272\345\272\217\350\241\250.h" | 83 ++++---- ...222\345\271\266\346\216\222\345\272\217.c" | 28 ++- ...242\347\232\204\345\210\244\345\256\232.c" | 18 +- ...214\346\254\241\346\226\271\347\250\213.c" | 86 +++++--- .../\347\273\203\344\271\240/unk_mdrprint.c" | 191 ++++++++++++------ ...234\346\225\260\346\270\270\346\210\217.c" | 16 +- ...250\346\225\260\346\211\253\346\217\217.c" | 4 +- ...\347\232\204BMI\346\265\213\350\257\225.c" | 15 +- ...223\350\256\241\347\256\227\345\231\250.c" | 9 +- ...240\346\225\260\345\210\206\350\247\243.c" | 8 +- .../\351\241\271\347\233\256/mdrOS/kheap.c" | 113 +++++++---- .../\351\241\271\347\233\256/mdrOS/memory.c" | 54 +++-- .../\351\241\271\347\233\256/mdrOS/printf.h" | 6 +- 27 files changed, 567 insertions(+), 347 deletions(-) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\210\235\350\257\206HAL\345\272\223.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\210\235\350\257\206HAL\345\272\223.md" index 92625c3..3ce5101 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\210\235\350\257\206HAL\345\272\223.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\210\235\350\257\206HAL\345\272\223.md" @@ -1,11 +1,13 @@ # 初识HAL 在比较漫长的汇编语言时代,很多程序员都习惯用位操作对底层硬件进行编写,其优点有以下等: + - 代码直观 - 代码执行效率高 - 代码体积小 缺点有以下等: + - 代码可读性差 - 代码移植性差 - 代码维护性差 @@ -23,6 +25,7 @@ HAL库的设计目的正是为此,从而使开发者更容易地移植和维 ![CMSIS结构图](/images/嵌入式/CMSIS架构图.png) CMSIS包括以下几个关键部分: + 1. **CMSIS-Core**:提供了一个基本框架,包括用于启动、中断处理、内存管理和异常处理的通用函数。 2. **CMSIS-DSP**:提供了一个数字信号处理(DSP)的软件库,包含了用于信号处理操作的函数。 3. **CMSIS-RTOS**:提供了一个实时操作系统(RTOS)接口,允许开发者选择并集成不同的RTOS实现。 @@ -31,11 +34,10 @@ CMSIS包括以下几个关键部分: 通过使用CMSIS,开发者可以编写与硬件无关的代码,只需针对特定的微控制器进行一些小的修改或配置,就可以在不同的微控制器上运行。这极大地提高了开发效率,并简化了微控制器软件的维护和更新。 - - - ## HAL库介绍 + ST为了方便用户开发STM32芯片开发提供了三种库: + 1. 标准外设库(Standard Peripheral Libraries): - ST最早的库,现在还在用 - 目前只兼容 F0/F1/F3/F2/F4/L1 系列 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\257\204\345\255\230\345\231\250\347\274\226\347\250\213.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\257\204\345\255\230\345\231\250\347\274\226\347\250\213.md" index 67d8cf4..af919db 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\257\204\345\255\230\345\231\250\347\274\226\347\250\213.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\345\257\204\345\255\230\345\231\250\347\274\226\347\250\213.md" @@ -18,4 +18,4 @@ 寄存器的设计和优化对计算机的性能有着重要影响,因此现代CPU通常会有大量的寄存器,并且会采用各种技术来提高它们的访问速度和效率。 -## 2. \ No newline at end of file +## 2 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\346\234\257\350\257\255\350\241\250.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\346\234\257\350\257\255\350\241\250.md" index c691a79..082ba59 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\346\234\257\350\257\255\350\241\250.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\346\234\257\350\257\255\350\241\250.md" @@ -6,6 +6,7 @@ 一种专门设计用来满足实时计算需求的操作系统。实时操作系统必须在规定的时间内完成特定任务,以保证系统的正确性和可靠性。实时系统通常分为硬实时(Hard Real-Time)和软实时(Soft Real-Time)系统。 以下是一些RTOS的主要特点: + 1. **确定性(Determinism)**: - RTOS提供确定性的任务调度,确保任务能够在预定的时间限制内完成。 2. **任务调度**: @@ -19,11 +20,13 @@ 6. **资源管理**: - RTOS有效管理CPU时间、内存和其他系统资源,以支持实时任务。 RTOS广泛应用于以下领域: + - **嵌入式系统**:如工业控制系统、汽车电子、医疗设备、航空航天等。 - **网络设备**:如路由器、交换机等网络基础设施。 - **消费电子**:如数字电视、智能手机等。 - + 一些知名的RTOS包括: + - VxWorks - QNX - RTLinux @@ -39,10 +42,12 @@ RTOS的选择取决于具体的应用需求,包括任务的实时性要求、 ## 板级支持包(Board Support Package,简称 BSP) 一组用于特定硬件平台的软件,它在该硬件平台上提供了硬件抽象层,使得操作系统或者用户应用能够在该硬件平台上运行。基本的BSP包含以下功能: + - **硬件初始化代码**:这些代码负责在系统启动时配置硬件组件,如CPU、内存、外设接口等,以确保它们处于正确的状态。 - **设备驱动程序**:将硬件组件向上抽象为面向应用的API,使操作系统和应用程序能够使用其与硬件设备进行交互。 更完善的还包括以下等: + - **系统启动代码**:包括引导加载程序(Bootloader)和其他初始化代码,这些代码负责启动操作系统。 - **配置工具和脚本**:用于配置和定制BSP的工具,以适应特定的硬件配置和操作系统需求。 - **调试和测试工具**:帮助开发人员调试和测试硬件与软件接口的工具。 @@ -70,6 +75,7 @@ BSP的主要目的是为了让操作系统和应用程序开发者不必关心 7. **可扩展性**: - UEFI的设计允许轻松添加新功能,使其能够适应未来的硬件和软件需求。 UEFI的主要组件包括: + - **UEFI固件**:这是嵌入在主板上的固件,负责初始化硬件并提供启动服务。 - **UEFI驱动程序**:用于在UEFI环境中操作硬件的软件模块。 - **UEFI Shell**:一个命令行界面,允许用户执行固件级别的操作。 @@ -84,6 +90,7 @@ BSP的主要目的是为了让操作系统和应用程序开发者不必关心 处理器架构是软件和硬件之间交互的桥梁,它决定了软件如何与硬件进行通信和操作。 以下是几种常见的处理器架构: + 1. **x86架构**:由Intel和AMD公司开发,是最常见的桌面和服务器处理器架构之一。它支持复杂指令集计算机(CISC)和虚拟化技术。 2. **ARM架构**:由ARM Holdings公司开发,主要用于移动设备和嵌入式系统。它支持精简指令集计算机(RISC)架构,并以其低功耗和高能效而闻名。 3. **MIPS架构**:由MIPS Technologies公司开发,是一种精简指令集计算机(RISC)架构。它曾经在许多工作站和服务器中使用,但现在更多地用于嵌入式系统。 @@ -92,6 +99,7 @@ BSP的主要目的是为了让操作系统和应用程序开发者不必关心 6. **RISC-V架构**:是一个开源的指令集架构,旨在成为现代处理器架构的标准。它支持精简指令集计算机(RISC)架构,并以其模块化和可扩展性而受到关注。 处理器架构的选择取决于多种因素,包括性能需求、能效、成本、生态系统支持、兼容性和特定应用场景。例如: + - ARM架构因其低功耗和高能效而广泛用于移动设备 - x86架构因其高性能和广泛的应用软件支持而成为桌面和服务器系统的首选 @@ -100,21 +108,24 @@ BSP的主要目的是为了让操作系统和应用程序开发者不必关心 处理器架构的一部分,它定义了处理器可以理解和执行的机器指令的集合。指令集是软件和硬件之间的接口,它规定了处理器可以执行的操作,以及如何通过操作码和操作数来执行这些操作。 指令集可以分为以下几种类型: + 1. **复杂指令集计算机(CISC)**:这种类型的指令集包含大量的指令,每个指令可以执行多个操作。CISC架构的处理器通常具有复杂的指令解码器,能够解析和执行复杂的指令。这种架构的优点是每个指令可以完成更多的操作,从而减少总的指令数量。然而,复杂的指令解码和执行可能会导致性能下降。 2. **精简指令集计算机(RISC)**:这种类型的指令集包含较少的指令,每个指令只执行一个简单的操作。RISC架构的处理器通常具有简单的指令解码器,能够快速解析和执行简单的指令。这种架构的优点是指令解码和执行速度快,但需要更多的指令来完成复杂的操作。 3. **混合指令集计算机**:这种类型的指令集结合了CISC和RISC的特点,包含一定数量的复杂指令和简单指令。这种架构的处理器可以根据需要使用复杂的指令或简单的指令来执行操作。 - + 指令集的选择取决于多种因素,包括性能需求、能效、成本、生态系统支持、兼容性和特定应用场景。例如: + - CISC架构的处理器因其能够执行复杂操作而广泛用于桌面和服务器系统 - RISC架构的处理器因其简单高效的指令解码和执行而广泛用于移动设备和嵌入式系统 ## CMSIS(Cortex Microcontroller Software Interface Standard) -一个为ARM Cortex-M微控制器系列设计的标准化软件接口。它旨在为开发者提供一个统一的接口,使得在不同ARM Cortex-M微控制器之间移植和复用软件变得更加容易。CMSIS的目的是减少为不同微控制器编写软件的复杂性,并允许开发者更容易地从一个微控制器迁移到另一个微控制器。 +一个为ARM Cortex-M微控制器系列设计的标准化软件接口。它旨在为开发者提供一个统一的接口,使得在不同ARM Cortex-M微控制器之间移植和复用软件变得更加容易。CMSIS的目的是减少为不同微控制器编写软件的复杂性,并允许开发者更容易地从一个微控制器迁移到另一个微控制器。 ![CMSIS结构图](/images/嵌入式/CMSIS架构图.png) CMSIS包括以下几个关键部分: + 1. **CMSIS-Core**:提供了一个基本框架,包括用于启动、中断处理、内存管理和异常处理的通用函数。 2. **CMSIS-DSP**:提供了一个数字信号处理(DSP)的软件库,包含了用于信号处理操作的函数。 3. **CMSIS-RTOS**:提供了一个实时操作系统(RTOS)接口,允许开发者选择并集成不同的RTOS实现。 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\216\257\345\242\203\346\220\255\345\273\272.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\216\257\345\242\203\346\220\255\345\273\272.md" index dcf347e..07f306d 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\216\257\345\242\203\346\220\255\345\273\272.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\216\257\345\242\203\346\220\255\345\273\272.md" @@ -22,27 +22,29 @@ Keil操作简单,容易上手,而且可以很方便地进行调试。 ### 1.1 工具安装 -1. [ **STM32CubeMX** ](https://www.st.com/en/development-tools/stm32cubemx.html) - - ST官方出的一款针对ST的MCU/MPU跨平台的图形化工具, +1. [**STM32CubeMX**](https://www.st.com/en/development-tools/stm32cubemx.html) + + ST官方出的一款针对ST的MCU/MPU跨平台的图形化工具, 支持在Linux、MacOS、Window系统下开发,其对接的底层接口是HAL库, 另外习惯于寄存器开发的同学们,也可以使用LL库。STM32CubeMX除了集成MCU/MPU的硬件抽象层, 另外还集成了像RTOS,文件系统,USB,网络,显示,嵌入式AI等中间件,这样开发者就能够很轻松的完成MCU/MPU的底层驱动的配置, 留出更多精力开发上层功能逻辑,能够更进一步提高了嵌入式开发效率。 -2. [ **OpenOCD** ](https://github.com/xpack-dev-tools/openocd-xpack/releases) +2. [**OpenOCD**](https://github.com/xpack-dev-tools/openocd-xpack/releases) openocd全名叫做Open On-Chip Debugger,是一个自由开放的片上调试工具和编程工具, 目前已经发布到0.11.0版本,目前主流调试器几乎都支持。 - + 安装好之后,添加环境变量: ![OpenOCD环境变量](/images/嵌入式/OpenOCD环境变量图.png) 在终端输入,进行测试: + ```shell openocd ``` + 如果有信息输出如下,那就是装好了。 ![OpenOCD检查](/images/嵌入式/OpenOCD检查图.png) @@ -50,48 +52,49 @@ Keil操作简单,容易上手,而且可以很方便地进行调试。 3. MinGW Clion需要使用MinGW环境来配置工具链,安装在网上有很多教程,这里就不赘述了。 - + 安装好之后,添加到环境变量: ![MinGW环境变量](/images/嵌入式/MinGW环境变量图.png) 在终端输入,进行测试: + ```shell gcc -v ``` + 如果有信息输出如下,那就是装好了。 ![MinGW检查](/images/嵌入式/MinGW检查图.png) -4. [ **arm-none-eabi-gcc** ](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) +4. [**arm-none-eabi-gcc**](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) - > 注:为什么不是gcc? - > + > 注:为什么不是gcc? + > > 在开发stm32的时候,编译工具链要使用gcc-arm-none-eabi,为什么不是gcc呢? > 这就要说到Win下的交叉编译了,因为我们要在PC机上编译出可以运行在ARM上的程序, > 使用gcc编译出的是在PC上运行的程序,所以我们要使用gcc-arm-none-eabi进行交叉编译,才能运行在ARM上。 安装好后,添加到环境变量: ![GNU-arm-none-eabi环境变量](/images/嵌入式/GNU-arm-none-eabi环境变量图.png) - + 在终端输入,进行测试: + ```shell arm-none-eabi-gcc -v ``` + 如果有信息输出如下,那就是装好了。 ![GNU-arm-none-eabi检查](/images/嵌入式/GNU-arm-none-eabi检查图.png) 5. CLion - - 安装见[ **CLion** ](/杂项/工具和环境/工具/编程工具.md#1-文本编辑器和代码编辑器) + + 安装见[**CLion**](/杂项/工具和环境/工具/编程工具.md#1-文本编辑器和代码编辑器) 配置CLion的工具链,如下: - + ![CLion设置工具链](/images/嵌入式/CLion设置工具链图.png) 配置CLion的STM32开发方式,如下: - - ![CLion的STM32开发配置](/images/嵌入式/CLion的STM32开发配置图.png) - - + ![CLion的STM32开发配置](/images/嵌入式/CLion的STM32开发配置图.png) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\250\213\345\272\217\344\270\213\350\275\275\344\270\216\350\260\203\350\257\225.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\250\213\345\272\217\344\270\213\350\275\275\344\270\216\350\260\203\350\257\225.md" index 282ef24..1f082b6 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\250\213\345\272\217\344\270\213\350\275\275\344\270\216\350\260\203\350\257\225.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\345\265\214\345\205\245\345\274\217/\347\250\213\345\272\217\344\270\213\350\275\275\344\270\216\350\260\203\350\257\225.md" @@ -8,7 +8,6 @@ | 1 | 0 | 系统储存器 | 即是Bootloader固件所在地 | | 1 | 1 | SRAM储存器 | 在SRAM中调试代码 | - ## 1. 串口下载 > 在一般的STM32最小系统板上都带有串口下载电路,这里使用STM32F103C8T6板子。 @@ -29,7 +28,6 @@ CH340的上位机接口是一根USB线,连接到电脑的USB口上,而它的 ### 1.3 软件下载 -这里使用[ **FlyMCU** ](http://www.mcuisp.com/chinese%20mcuisp%20web/ruanjianxiazai-chinese.htm)串口下载器, +这里使用[**FlyMCU**](http://www.mcuisp.com/chinese%20mcuisp%20web/ruanjianxiazai-chinese.htm)串口下载器, ### 1.4 ISP原理分析 - diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/34_\344\275\215\346\223\215\344\275\234.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/34_\344\275\215\346\223\215\344\275\234.md" index c6792db..27b375c 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/34_\344\275\215\346\223\215\344\275\234.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/34_\344\275\215\346\223\215\344\275\234.md" @@ -9,7 +9,7 @@ - 每一个位存储一个二进制码(记作 **0** 或 **1**) 2. 对于 **整型** 数据来说,每个计算机位对应这个整数二进制表示中的一个位 3. 8 位构成一个 **字节**,因此 ***在常见的实现中***,`int` 类型有 **4** 字节(*32* 位),`long long` 有 **8** 字节(*64* 位) -4. 关于进制的知识,可以参考 [ **进制** ](/教程/番外/77_关于进制.md) +4. 关于进制的知识,可以参考 [**进制**](/教程/番外/77_关于进制.md) ### 1.2 整数的二进制表示(以一字节为例) @@ -27,7 +27,6 @@ > 只能使用 **整型** 数据进行位操作,不能使用 ~~**~~浮点型~~**~~ 数据; - ### 2.1 位操作的种类 > 下面的例子使用无符号 8 位整数进行演示: @@ -60,7 +59,7 @@ ```C ~(10011010) // 表达式 - 01100101 // 结果值 + 01100101 // 结果值 ``` 5. 按位左移 (<<): @@ -125,12 +124,12 @@ uint32_t flag = 0b1111111100000000000000000000000000000000; ```C //typedef unsigned char uint8_t; - + uint8_t flag = 0b10101010; - + //定义MASK,0号位为1,其余位为0 uint8_t mask = 0b00000010; - + //掩码操作 flag = flag & mask; //此时 flag = 0b00000010 ``` @@ -176,11 +175,11 @@ uint32_t flag = 0b1111111100000000000000000000000000000000; - 使用 `&` 运算符和掩码,代码如下: - 以上一节的 **mask**(只有 `1` 号位为 1)为例: - ```C + ```C uint8_t flag = 0b10101011; if ((flag & mask) == mask) { printf("1号位为1。"); - } + } ``` 根据 **mask** 中为 `1` 的位, 在 **flag** 中只读对应。 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" index 0aefcce..dba27d2 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" @@ -8,7 +8,6 @@ [Limine - C Template](https://github.com/limine-bootloader/limine-c-template) - ## 自制引导用户 通常你们需要的准备工作要求更多,且编写后的操作系统运行的介质非常有限 @@ -23,17 +22,17 @@ github上有很多使用Multiboot的自制OS实例, 可以借鉴其是如何搭 ## 目录结构 -``` -┌ target (目标文件目录, 存放编译好等待链接的目标文件) +```text +├ target (目标文件目录, 存放编译好等待链接的目标文件) ├ src (源文件目录, 存放操作系统的所有C和汇编源码) -| ├ boot (存放引导程序的源码文件) -| ├ kernel (存放内核的核心功能源码文件, 如中断管理, 多进程, 内存管理等) -| ├ util (存放一些工具函数实现, 如各种数据结构实现,printf实现等) -| ├ driver (存放内核内置驱动的源码实现) -| ├ fs (存放文件系统的源码实现) -| ├ include (存放各种头文件) -| └ sysapp (存放系统内置程序, 如shell) -├ isodir (将最终的内核文件以及所有需要的资源文件到这里的最终目标目录, 等待引导实现程序打包成ISO等映像) +│ ├ boot (存放引导程序的源码文件) +│ ├ kernel (存放内核的核心功能源码文件, 如中断管理, 多进程, 内存管理等) +│ ├ util (存放一些工具函数实现, 如各种数据结构实现,printf实现等) +│ ├ driver (存放内核内置驱动的源码实现) +│ ├ fs (存放文件系统的源码实现) +│ ├ include (存放各种头文件) +│ └ sysapp (存放系统内置程序, 如shell) +├ isodir (将最终的内核文件以及所有需要的资源文件到这里的最终目标目录, 等待引导实现程序打包成ISO等映像) ├ apps (操作系统内置的应用程序源码, 一般放置移植或自己开发的各种小程序, 如lua解释器, SDL2图形库等) └ i686_elf_tools (交叉编译工具链) ``` @@ -48,38 +47,38 @@ github上有很多使用Multiboot的自制OS实例, 可以借鉴其是如何搭 ```linker ENTRY(_start) - + SECTIONS { - - . = 2M; - - .text BLOCK(4K) : ALIGN(4K) - { - code = .; _code = .; __code = .; - *(.multiboot) - *(.text) - } - - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } - - .data BLOCK(4K) : ALIGN(4K) - { - data = .; _data = .; __data = .; - *(.data) - } - - .bss BLOCK(4K) : ALIGN(4K) - { - bss = .; _bss = .; __bss = .; - *(COMMON) - *(.bss) - } - - end = .; _end = .; __end = .; + + . = 2M; + + .text BLOCK(4K) : ALIGN(4K) + { + code = .; _code = .; __code = .; + *(.multiboot) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + data = .; _data = .; __data = .; + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + bss = .; _bss = .; __bss = .; + *(COMMON) + *(.bss) + } + + end = .; _end = .; __end = .; } ``` @@ -91,7 +90,7 @@ SECTIONS #### 根目录构建脚本 -```Makefile +```make clean: # 目录清理 rm target/* @@ -109,18 +108,18 @@ linker: #### 子目录脚本示例 -```Makefile +```make gcc := /i686_elf_tools/bin/i686-elf-gcc #交叉编译器的路径 incpath_src := ../include/ #头文件目录路径 out_path_src := ../target/ #根据你的子目录相对于根目录的深度编写 ../的个数 obj_dos := $(out_path_src)源文件名.obj ... #填写你所有的源文件对应的目标文件名 (源文件名.obj) default : $(obj_dos) - + $(out_path_src)%.o : %.c Makefile #C源文件构建 - $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o + $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o $(out_path_src)%.obj : %.asm Makefile - nasm -f elf $*.asm -o $(out_path_src)$*.obj + nasm -f elf $*.asm -o $(out_path_src)$*.obj ``` ### Python @@ -269,4 +268,4 @@ if a != 0: exit(-1) print("Launching i386 vm...") -``` \ No newline at end of file +``` diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/interrupt.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/interrupt.md" index 35fe969..bba030e 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/interrupt.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/interrupt.md" @@ -30,13 +30,13 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int ### 异常中断 -异常中断是非可屏蔽中断, 由CPU内部触发,用于向正在运行的内核发出需要其处理的一些异常。 +异常中断是非可屏蔽中断, 由CPU内部触发,用于向正在运行的内核发出需要其处理的一些异常。 在Intel规定中,前32个中断向量被留为异常 * 在中断流程里发生异常中断叫 `Double Fault` * 在 `Doubel Fault` 里再次发生中断叫 `Triple Fault` -> 当发生 `Triple Fault` 类型中断时候, 计算机系统意识到发生了内核无法解决的严重错误, +> 当发生 `Triple Fault` 类型中断时候, 计算机系统意识到发生了内核无法解决的严重错误, > 这个时候计算机系统会越过ACPI等电源的设置迅速进行重启。 以下是一份IDT各种异常的对照表 @@ -45,14 +45,12 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int [**OSDEV Exceptions**](https://wiki.osdev.org/Exceptions) OSDEV网站有对异常中断作详细的解释 - ### 中断请求 (IRQ) 或硬件中断 这种类型的中断由芯片组在外部产生,并通过锁定到相关 CPU 的 #INTR 引脚或等效信号来发出信号。属于可屏蔽中断的一种。 > 在最初的32系统开发中, 我们会接触到一个叫做8259A的可编程中断控制器 - ### 软中断 这类中断通常由用户程序触发, 一般用于 Syscall 系统调用等功能,属于可屏蔽中断的一种 @@ -66,6 +64,7 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int > 通常, 我们建议你将这些结构体定义在头文件中, 以方便我们在其他地方复用它们 1. 中断门描述符结构体 + ```c struct idt_entry_struct { uint16_t base_low; @@ -77,8 +76,9 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int typedef struct idt_entry_struct idt_entry_t; ``` - + 2. IDT指针声明 + ```c struct idt_ptr_struct { uint16_t limit; @@ -87,16 +87,18 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int typedef struct idt_ptr_struct idt_ptr_t; ``` - + 3. 以及一些函数的预定义 + ```c void idt_install(); //IDT初始化 void idt_use_reg(uint8_t num,uint32_t base); //注册用户程序可触发的中断, 这个在我们以后写到syscall时候要用 void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags); //注册一般中断 ``` - + 4. 汇编定义的ISR处理函数 + ```c #define DECLARE_ISR(i) extern void isr##i(); @@ -156,6 +158,7 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int ``` 5. 中断触发前的CPU各种寄存器状态以及中断号等 + ```c typedef struct registers { uint32_t ds; // 我们自己弹入的,当前数据段 @@ -167,6 +170,7 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int ``` 6. 方便内核注册中断处理函数以及一些其他定义 + ```c #define IRQ0 32 #define IRQ1 33 @@ -307,6 +311,7 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int ``` 3. C语言中的中断预处理函数, 由汇编调用 + ```c void isr_handler(registers_t regs) { //printf("\n[Kernel]: received interrupt: %d\n",regs.int_no); 这里你可以输出一下异常中断号,也可以不输出 @@ -333,5 +338,4 @@ IDT有特殊的标志位规定某些中断是否可以由用户程序使用 `int [**interrupt.asm**](/教程/示例代码/项目/mdrOS/interrupt.asm) - 到这里, 我们内核就基本具备了对中断的处理能力, 以后编写程序驱动, 异常处理都可以通过我们已经编写好的函数去注册 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/memory.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/memory.md" index 3de81fa..3f5ade1 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/memory.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/memory.md" @@ -30,7 +30,6 @@ * 段界限(20位),占据描述符的第0~15位和第48~51位,前者存储低16位,后者存储高4位。 * 段属性(12位),占据描述符的第39~47位和第49~55位,段属性可以细分为8种:TYPE属性、S属性、DPL属性、P属性、AVL属性、L属性、D/B属性和G属性。 - ### 如何配置 在32位保护模式下, GDT的配置是必须的。这里我们用C配置一个简易的GDT, 方便我们后期使用分页式内存管理 @@ -58,8 +57,8 @@ uint32_t base; } __attribute__((packed)) gdt_ptr_t; - - void gdt_install(); + + void gdt_install(); ``` 2. 源文件 @@ -122,7 +121,6 @@ ret ; 刷新完毕,返回 ``` - ## 分页式内存管理 在分页系统下,一个程序发出的虚拟地址由两部分组成: 页面号和页内偏移值。 @@ -152,7 +150,6 @@ MMU依赖于页表来进行一切与页面有关的管理活动,这些活动 > 页框不止可以以4kb为大小, 你也可以设置为4MB、1GB等大小。但是那样的页太大了,一般用于64位更大的内存上管理 - 由于C代码对于内存管理整个模块的耦合性较高, 无法单独将代码片段完整展示出来。故列出了所有的源文件 * [**kheap.c**](/教程/示例代码/项目/mdrOS/kheap.c) 内核堆实现 @@ -160,7 +157,7 @@ MMU依赖于页表来进行一切与页面有关的管理活动,这些活动 * [**memory.h**](/教程/示例代码/项目/mdrOS/memory.h) 各种结构的预定义 * [**memory.c**](/教程/示例代码/项目/mdrOS/memory.c) 常用内存操作函数 -> 其中可以删除有关task的代码, 该代码是多进程的一部分实现。我们没进行到多进程那一步可以先不用, +> 其中可以删除有关task的代码, 该代码是多进程的一部分实现。我们没进行到多进程那一步可以先不用, > 现在首要任务是确保我们所写的分页式内存管理可用 ## 堆内存管理 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/video_driver.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/video_driver.md" index a157770..736b142 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/video_driver.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/video_driver.md" @@ -11,6 +11,7 @@ 其显存基址为 `0xB8000` > 注意: UEFI引导方式不存在这块区域, UEFI的显存区域由`BootService`提供给你 +> ### 编写VGA视频驱动程序 1. 准备工作 @@ -26,12 +27,13 @@ asm volatile("outb %b0, %w1" : : "a"(data), "Nd"(port)); } ``` - + * 关于`0xB8000`: 在OS代码中一般用16进制表示一些内存地址, 这样代码展现比较直观好辨认, 相比十进制或者二进制, 代码长度也会有所缩减 - [关于进制的知识](/教程/番外/77_关于进制.md) - + [关于进制的知识](/教程/番外/77_关于进制.md) + 2. 实现滚屏 光标位置设置 + ```c static void scroll() { //滚屏代码实现 uint8_t attributeByte = (0 << 4) | (15 & 0x0F); @@ -102,15 +104,13 @@ } ``` -> 什么? 你问我printf函数怎么实现?
+> 什么? 你问我printf函数怎么实现? > 别着急, 请看下面 [MdrOS的printf函数实现](/教程/示例代码/项目/mdrOS/printf.c) - - ## VBE (VESA BIOS EXTENSION) VESA BIOS扩展 -> SVGA (Super VGA) \ +> **SVGA (Super VGA)** \ > IBM的VGA标准是显示卡发展史上的一块丰碑。 > 但后来无法满足人们的需要,于是市场上出现了TVGA、S3系列、 > Cirrus Logic、ET等为首的一批显示卡,提供了比VGA分辨率更高,颜色更丰富的显示模式, @@ -126,10 +126,10 @@ ## 如何开启VBE模式 > 操作系统开发前期我们不是很建议您使用VBE模式, -以LegacyBIOS为例,我们刚进入引导一般都是VGA模式,这种显示模式的功能非常有限,只能打印字符和少许的颜色
+以LegacyBIOS为例,我们刚进入引导一般都是VGA模式,这种显示模式的功能非常有限,只能打印字符和少许的颜色 而进入VBE高分辨率显示模式,我们可以自由绘画图形, 可以显示的颜色升级为RGB 1. 在16位实模式中开启VBE显示模式 ```c - ``` \ No newline at end of file + ``` diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/\351\241\271\347\233\256\346\246\202\350\277\260.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/\351\241\271\347\233\256\346\246\202\350\277\260.md" index 99e7281..064d151 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/\351\241\271\347\233\256\346\246\202\350\277\260.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/\351\241\271\347\233\256\346\246\202\350\277\260.md" @@ -5,15 +5,15 @@ ## 概念 -

操作系统是一种系统软件,它是控制管理计算机系统的硬软件,分配调度资源的管理者

-

其内部功能有:

+操作系统是一种系统软件,它是控制管理计算机系统的硬软件,分配调度资源的管理者 +其内部功能有: * 内存管理 * 设备驱动 * 中断处理 * 任务调度 -#### 计算机启动过程 +### 计算机启动过程 1. 电源键按下 2. POST加电硬件自检 @@ -26,10 +26,12 @@ ## 环境准备 您需要: + * [i686-elf-tools](https://github.com/lordmilko/i686-elf-tools/releases/tag/13.2.0) 交叉编译工具链 * [nasm](https://nasm.us/) 汇编编译器 以及(选择性): + * [Python3](https://www.python.org/downloads/) 充当构建脚本 * [Makefile](https://www.gnu.org/software/make/) 充当构建脚本 @@ -69,4 +71,4 @@ * 64位长的操作系统会比32位保护模式的操作系统实现更难, 比如32位只需要二级页表即可,64位需要4级甚至更多才能管理所有内存 * ARM等其他架构的CPU与x86平台的CPU实现截然不同, 其中x86的很多机制在ARM是没有的, 同理ARM某些机制x86也没有 * 本教程只是教学您如何实现一个最简单的宏内核操作系统,如果您想完善您的操作系统, 可以去查阅更多的资料 -* 操作系统编写好都是要在实体机上测试的, 无法在实体机上跑的操作系统就不是一个真正的操作系统 \ No newline at end of file +* 操作系统编写好都是要在实体机上测试的, 无法在实体机上跑的操作系统就不是一个真正的操作系统 diff --git "a/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" "b/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" index 2ba74ce..d19b58c 100644 --- "a/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" +++ "b/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" @@ -3,14 +3,17 @@ ## 1. 什么是进制 我们通常都是基于数字10来表示数字,比如2157,千位为2、百位为1、十位为5、个位为7,由此,我们可以得出一个等式 + ```C 2157 == 2 * 10^3 + 1 * 10^2 + 5 * 10^1 + 7 * 10^0 ``` + 因为这种方法是基于10的幂,所以称以10为基底书写2157 姑且认为这种书写方法是得益于我们有10根手指。从某种意义上看,计算机只有2根手指,只能表示0和1,因此,计算机适用于基底为2的数制系统。 它使用2的幂而不是10的幂。以2为基底表示的数统称为 **二进制数** ( _binary number_ ), 二进制中的2和十进制中的10作用一样,都是基数,而2的幂则相当于十进制中的10的幂。例如: + ```C 1011 == 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 ``` @@ -22,12 +25,15 @@ ### 1.1 **二进制** 二进制字面量以 `0b` 或 `0B` 开头,后面跟着二进制数字(0 和 1)。例如: + ```C int binary = 0b1010; // 二进制 1010,十进制 10 ``` + ### 1.2 **八进制** 八进制字面量以 `0` 开头,后面跟着八进制数字(0-7)。例如: + ```C int octal = 012; // 八进制 12,十进制 10 ``` @@ -35,7 +41,7 @@ int octal = 012; // 八进制 12,十进制 10 每个八进制位都对应一个 **3** 位二进制数 ( 即 **3** 个二进制位 ), 下图列出了八进制和二进制之间的对应关系: -> **注意**:转换的时候不能省略中间的 `0` +> **注意**:转换的时候不能省略中间的 `0` | 十进制 | 八进制 | 对应二进制 | |-------|-------|-------| @@ -53,6 +59,7 @@ int octal = 012; // 八进制 12,十进制 10 ### 1.3 **十进制** 十进制字面量是默认的表示方法,不需要前缀。例如: + ```C int decimal = 10; // 十进制 10 ``` @@ -63,6 +70,7 @@ int decimal = 10; // 十进制 10 所以我们用字母 `A ~ F` ( `a ~ f` )来表示。 十六进制字面量以 `0x` 或 `0X` 开头,后面跟着十六进制数字(0-9 和 a-f 或 A-F)。例如: + ```C int hexadecimal = 0xA; // 十六进制 A,十进制 10 ``` diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/linkfix.py" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/linkfix.py" index bdf8d85..b77cdfa 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/linkfix.py" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/linkfix.py" @@ -1,8 +1,9 @@ # coding=utf-8 from os import walk from os.path import join -for path, _, files in walk('.'): + +for path, _, files in walk("."): for file in files: - if not file.endswith('.md'): - with open(join(path, file) + '.md', 'w') as f: - f.write(f"# {file}\n\n[{file}](./{file} ':include')\n") \ No newline at end of file + if not file.endswith(".md"): + with open(join(path, file) + ".md", "w") as f: + f.write(f"# {file}\n\n[{file}](./{file} ':include')\n") diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\210_\346\225\260\347\273\204_1.h" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\210_\346\225\260\347\273\204_1.h" index 2d8da84..5ce5685 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\210_\346\225\260\347\273\204_1.h" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\210_\346\225\260\347\273\204_1.h" @@ -15,41 +15,50 @@ typedef struct int top; } Stack; -void initStack(Stack* s) +void initStack(Stack *s) { s->top = -1; - for (int i = 0; i < cap; i++) { + for (int i = 0; i < cap; i++) + { s->array[i] = 0; } } -void push(Stack* s, ElementType e) +void push(Stack *s, ElementType e) { - if (s->top == cap - 1) { + if (s->top == cap - 1) + { printf("Stack Overflow\n"); - } else { + } + else + { s->array[++s->top] = e; } } -ElementType pop(Stack* s) +ElementType pop(Stack *s) { - if (s->top == -1) { + if (s->top == -1) + { printf("Stack Underflow\n"); return 0; } return s->array[s->top--]; } -void printStack(const Stack* s) +void printStack(const Stack *s) { printf("%d element", s->top + 1); - if (s->top == -1 || s->top == 0) { + if (s->top == -1 || s->top == 0) + { printf(": [ "); - } else { + } + else + { printf("s: [ "); } - for (int i = 0; i <= s->top; i++) { + for (int i = 0; i <= s->top; i++) + { printf("%d ", s->array[i]); } printf("]\n"); diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\351\241\272\345\272\217\350\241\250.h" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\351\241\272\345\272\217\350\241\250.h" index b6d2651..984856b 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\351\241\272\345\272\217\350\241\250.h" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/\351\241\272\345\272\217\350\241\250.h" @@ -12,16 +12,18 @@ constexpr int g_initCap = 4; typedef int ElementType; -typedef struct { - ElementType* arr; - size_t size; // length of the sequence list +typedef struct +{ + ElementType *arr; + size_t size; // length of the sequence list size_t capacity; // size of the array } SeqList; -void initSeqList(SeqList* l) +void initSeqList(SeqList *l) { - l->arr = (ElementType*)malloc(sizeof(ElementType) * g_initCap); - if (!(l->arr)) { + l->arr = (ElementType *)malloc(sizeof(ElementType) * g_initCap); + if (!(l->arr)) + { printf("Initialization failed!\n"); exit(-1); } @@ -29,44 +31,48 @@ void initSeqList(SeqList* l) l->capacity = g_initCap; } -void initSeqListFromArray(SeqList* l, const ElementType* a, int length) +void initSeqListFromArray(SeqList *l, const ElementType *a, int length) { - l->arr = (ElementType*)malloc(sizeof(ElementType) * length); - if (!(l->arr)) { + l->arr = (ElementType *)malloc(sizeof(ElementType) * length); + if (!(l->arr)) + { printf("Initialization failed!\n"); exit(-1); } - for (size_t n = 0; n < length; ++n) { + for (size_t n = 0; n < length; ++n) + { l->arr[n] = a[n]; } l->size = length; l->capacity = length; } -void clearSeqList(SeqList* l) +void clearSeqList(SeqList *l) { free(l->arr); initSeqList(l); } -bool isSeqListEmpty(const SeqList* l) { return l->size == 0; } +bool isSeqListEmpty(const SeqList *l) { return l->size == 0; } -size_t lengthOfSeqList(const SeqList* l) { return l->size; } +size_t lengthOfSeqList(const SeqList *l) { return l->size; } -ElementType getFromSeqList(const SeqList* l, int i) +ElementType getFromSeqList(const SeqList *l, int i) { - if (i >= l->size) { + if (i >= l->size) + { printf("Index out of bound!\n"); return 0; } return l->arr[i]; } -void expandSeqList(SeqList* l) +void expandSeqList(SeqList *l) { printf("Expansion\n"); - ElementType* newArr = (ElementType*)realloc(l->arr, sizeof(ElementType) * 2 * l->capacity); - if (!(newArr)) { + ElementType *newArr = (ElementType *)realloc(l->arr, sizeof(ElementType) * 2 * l->capacity); + if (!(newArr)) + { printf("Expansion failed!\n"); exit(-1); } @@ -74,11 +80,12 @@ void expandSeqList(SeqList* l) l->arr = newArr; } -void curtailSeqList(SeqList* l) +void curtailSeqList(SeqList *l) { printf("Curtailment\n"); - ElementType* newArr = (ElementType*)realloc(l->arr, sizeof(ElementType) * l->capacity / 2); - if (!newArr) { + ElementType *newArr = (ElementType *)realloc(l->arr, sizeof(ElementType) * l->capacity / 2); + if (!newArr) + { printf("Curtailment failed!\n"); exit(-1); } @@ -86,54 +93,62 @@ void curtailSeqList(SeqList* l) l->arr = newArr; } -void insertBack2SeqList(SeqList* l, ElementType x) +void insertBack2SeqList(SeqList *l, ElementType x) { - if (l->size == l->capacity) { + if (l->size == l->capacity) + { expandSeqList(l); } l->arr[l->size] = x; l->size += 1; } -void insert2SeqList(SeqList* l, int i, ElementType x) +void insert2SeqList(SeqList *l, int i, ElementType x) { - if (l->size == l->capacity) { + if (l->size == l->capacity) + { expandSeqList(l); } - for (size_t n = l->size; n > i; --n) { + for (size_t n = l->size; n > i; --n) + { l->arr[n] = l->arr[n - 1]; } l->arr[i] = x; l->size += 1; } -void removeFromSeqList(SeqList* l, int i) +void removeFromSeqList(SeqList *l, int i) { if (i >= l->size) printf("Index out of bound!\n"); - for (size_t n = i; n < l->size - 1; ++n) { + for (size_t n = i; n < l->size - 1; ++n) + { l->arr[n] = l->arr[n + 1]; } l->size -= 1; - if ((l->size + 1) * 4 < l->capacity) { + if ((l->size + 1) * 4 < l->capacity) + { curtailSeqList(l); } } -int indexOfSeqList(const SeqList* l, ElementType x) +int indexOfSeqList(const SeqList *l, ElementType x) { - for (int n = 0; n < l->size; ++n) { - if (l->arr[n] == x) { + for (int n = 0; n < l->size; ++n) + { + if (l->arr[n] == x) + { return n; } } return -1; } -void printSeqList(const SeqList* l) +void printSeqList(const SeqList *l) { printf("cap: %zu size: %zu ==>", l->capacity, l->size); - for (size_t i = 0; i < l->size; ++i) { + for (size_t i = 0; i < l->size; ++i) + { printf(" [%zu]=%d", i, l->arr[i]); } printf("\n"); diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225/4_1_\345\275\222\345\271\266\346\216\222\345\272\217.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225/4_1_\345\275\222\345\271\266\346\216\222\345\272\217.c" index f6a5c10..70217e9 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225/4_1_\345\275\222\345\271\266\346\216\222\345\272\217.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225/4_1_\345\275\222\345\271\266\346\216\222\345\272\217.c" @@ -5,19 +5,21 @@ #include #include -int N[10] = { 13, 5, 9, 6, 11, 2, 4, 7, 1, 8 }; +int N[10] = {13, 5, 9, 6, 11, 2, 4, 7, 1, 8}; void merge(int A[], const int p, const int mid, const int r) { const int n1 = mid - p + 1; const int n2 = r - mid; - int* L = malloc((n1 + 1) * sizeof(int)); - int* R = malloc((n2 + 1) * sizeof(int)); - for (int i = 0; i < n1; i++) { + int *L = malloc((n1 + 1) * sizeof(int)); + int *R = malloc((n2 + 1) * sizeof(int)); + for (int i = 0; i < n1; i++) + { L[i] = A[p + i]; } L[n1] = INT_MAX; - for (int i = 0; i < n2; i++) { + for (int i = 0; i < n2; i++) + { R[i] = A[(mid + 1) + i]; } R[n2] = INT_MAX; @@ -34,11 +36,15 @@ void merge(int A[], const int p, const int mid, const int r) k += 1; } #else - for (; k <= r; k++) { - if (L[i] <= R[j]) { + for (; k <= r; k++) + { + if (L[i] <= R[j]) + { A[k] = L[i]; i += 1; - } else { + } + else + { A[k] = R[j]; j += 1; } @@ -50,7 +56,8 @@ void merge(int A[], const int p, const int mid, const int r) void merge_sort(int A[], int p, int r) { - if (p < r) { + if (p < r) + { int mid = (p + r) / 2; merge_sort(A, p, mid); merge_sort(A, mid + 1, r); @@ -61,7 +68,8 @@ void merge_sort(int A[], int p, int r) int main(void) { merge_sort(N, 0, 9); - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) + { printf("%d ", N[i]); } return 0; diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/2_\344\270\211\350\247\222\345\275\242\347\232\204\345\210\244\345\256\232.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/2_\344\270\211\350\247\222\345\275\242\347\232\204\345\210\244\345\256\232.c" index e25b55d..b9514b4 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/2_\344\270\211\350\247\222\345\275\242\347\232\204\345\210\244\345\256\232.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/2_\344\270\211\350\247\222\345\275\242\347\232\204\345\210\244\345\256\232.c" @@ -10,23 +10,29 @@ int main(void) bool right = false; bool isosceles = false; scanf("%lf %lf %lf", &a, &b, &c); - if (a == b && b == c) { + if (a == b && b == c) + { printf("Equilateral Triangle"); return 0; } - if (a == b || b == c || c == a) { + if (a == b || b == c || c == a) + { isosceles = true; } - if (a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b) { + if (a * a + b * b == c * c || b * b + c * c == a * a || a * a + c * c == b * b) + { right = true; } - if (right && isosceles) { + if (right && isosceles) + { printf("Isosceles Right Triangle"); } - if (right) { + if (right) + { printf("Right Triangle"); } - if (isosceles) { + if (isosceles) + { printf("Isosceles Triangle"); } return 0; diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/3_\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/3_\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.c" index 113062b..b901ecc 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/3_\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/3_\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.c" @@ -7,22 +7,27 @@ int sqrt_coefficient(int num) { - if (num < 0) { + if (num < 0) + { num = -num; } - for (int i = (int)ceil(sqrt(num)); i > 0; i--) { - if (num % (i * i) == 0) { + for (int i = (int)ceil(sqrt(num)); i > 0; i--) + { + if (num % (i * i) == 0) + { return i; } } return 1; } -void cancelling_2(int* denominator, int* n1) +void cancelling_2(int *denominator, int *n1) { const int minimal = *denominator < *n1 ? *denominator : *n1; - for (int i = minimal; i > 1; i--) { - if (*denominator / i * i == *denominator && *n1 / i * i == *n1) { + for (int i = minimal; i > 1; i--) + { + if (*denominator / i * i == *denominator && *n1 / i * i == *n1) + { *denominator /= i; *n1 /= i; break; @@ -30,16 +35,21 @@ void cancelling_2(int* denominator, int* n1) } } -void cancelling(int* denominator, int* n1, int* n2, const int delta) +void cancelling(int *denominator, int *n1, int *n2, const int delta) { - if (delta == 0) { + if (delta == 0) + { cancelling_2(denominator, n1); - } else { + } + else + { const int tmp1 = *n1 < *n2 ? *n1 : *n2; const int minimal = *denominator < tmp1 ? *denominator : tmp1; - for (int i = minimal; i > 1; i--) { - if (*denominator / i * i == *denominator && *n1 / i * i == *n1 && *n2 / i * i == *n2) { + for (int i = minimal; i > 1; i--) + { + if (*denominator / i * i == *denominator && *n1 / i * i == *n1 && *n2 / i * i == *n2) + { *denominator /= i; *n1 /= i; *n2 /= i; @@ -51,13 +61,18 @@ void cancelling(int* denominator, int* n1, int* n2, const int delta) void print_number(const int a, const int b, const int delta) { - if (delta < 0) { + if (delta < 0) + { printf("Two imaginary roots: x1 = %lg+%lgi, x2 = %lg-%lgi\n", -b / 2.0 / a, sqrt(-delta) / 2.0 / a, - -b / 2.0 / a, - sqrt(-delta) / 2.0 / a); - } else if (delta == 0) { + -b / 2.0 / a, + sqrt(-delta) / 2.0 / a); + } + else if (delta == 0) + { printf("Two real roots: x1 = x2 = %lg\n", -b / 2.0 / a); - } else { + } + else + { printf("Two real roots: x1 = %lg, x2 = %lg\n", (-b + sqrt(delta)) / 2.0 / a, (-b - sqrt(delta)) / 2.0 / a); } } @@ -66,17 +81,21 @@ void latex_numerator(int b, const int coefficient_part, int root_part) { printf("%d \\pm ", -b); bool imaginary = false; - if (root_part <= 0) { + if (root_part <= 0) + { root_part = -root_part; imaginary = true; } - if (coefficient_part != 1) { + if (coefficient_part != 1) + { printf("%d", coefficient_part); } - if (root_part != 1) { + if (root_part != 1) + { printf("\\sqrt{%d}", root_part); } - if (imaginary) { + if (imaginary) + { fputs("i", stdout); } } @@ -85,28 +104,39 @@ void latex(const int a, int b, const int delta) { int coefficient_part = sqrt_coefficient(delta); int root_part = delta; - if (coefficient_part > 1) { + if (coefficient_part > 1) + { root_part = delta / coefficient_part / coefficient_part; } int denominator = 2 * a; cancelling(&denominator, &b, &coefficient_part, delta); putchar('$'); - if (delta == 0) { - if (b > 0) { + if (delta == 0) + { + if (b > 0) + { putchar('-'); } - if (denominator > 1) { + if (denominator > 1) + { printf("\\frac{%d}{%d}", b, denominator); - } else { + } + else + { printf("%d", denominator); } - } else { - if (denominator > 1) { + } + else + { + if (denominator > 1) + { fputs("\\frac{", stdout); latex_numerator(b, coefficient_part, root_part); printf("}{%d}", denominator); - } else { + } + else + { latex_numerator(b, coefficient_part, root_part); } } diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_mdrprint.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_mdrprint.c" index 3f8d37b..9721de9 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_mdrprint.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_mdrprint.c" @@ -10,12 +10,14 @@ MDR_ALIAS signed char byte; -struct argument { +struct argument +{ byte type; byte plain_value[8]; }; -enum arg_type { +enum arg_type +{ mdr_int, mdr_long, mdr_long_long, @@ -38,15 +40,16 @@ enum arg_type { * s -> char* * banned: zd tu to tx tX hhn hn ln lln zn tn jn */ -struct arg_type_specifier { - bool is_long_long = false; // ll - bool is_long = false; // l - bool is_short = false; // s - bool is_byte = false; // ss +struct arg_type_specifier +{ + bool is_long_long = false; // ll + bool is_long = false; // l + bool is_short = false; // s + bool is_byte = false; // ss bool is_capital_long = false; // L - bool is_size_t = false; // z - bool is_ptrdiff_t = false; // t - bool is_int_max = false; // j + bool is_size_t = false; // z + bool is_ptrdiff_t = false; // t + bool is_int_max = false; // j }; bool is_specifier_integer(char c) @@ -59,24 +62,26 @@ bool is_specifier_float(char c) return c == 'f' || c == 'F' || c == 'e' || c == 'E' || c == 'a' || c == 'A' || c == 'g' || c == 'G'; } -void clear_buff(char* buff, int* buff_cnt) +void clear_buff(char *buff, int *buff_cnt) { *buff_cnt = 1; buff[*buff_cnt] = '\0'; } -bool judge_multiplexing(const char* format) +bool judge_multiplexing(const char *format) { bool result = true; - for (int i = 1; i < strlen(format); i++) { - if (format[i - 1] == '{' && format[i] == ':') { + for (int i = 1; i < strlen(format); i++) + { + if (format[i - 1] == '{' && format[i] == ':') + { result = false; } } return result; } -int mdr_print(char* restrict format, ...) +int mdr_print(char *restrict format, ...) { va_list args; va_start(args, format); @@ -87,7 +92,7 @@ int mdr_print(char* restrict format, ...) bool in_format_code = false; bool after_colon = false; - char buff[16] = { '%', '\0' }; + char buff[16] = {'%', '\0'}; int buff_cnt = 1; bool is_long = false; @@ -96,64 +101,89 @@ int mdr_print(char* restrict format, ...) char forward = '\0'; - struct argument* arguments = NULL; + struct argument *arguments = NULL; - if (multiplexed) { - arguments = (struct argument*)malloc(sizeof(struct argument) * MDR_PRINT_MAX_ARGUMENT_NUM); + if (multiplexed) + { + arguments = (struct argument *)malloc(sizeof(struct argument) * MDR_PRINT_MAX_ARGUMENT_NUM); int arg_max = 0; int arg_cnt = 0; struct arg_type_specifier specifiers = {}; - for (int i = 0; i < strlen(format); i++) { - if (format[i] == '{' && in_format_code == false) { + for (int i = 0; i < strlen(format); i++) + { + if (format[i] == '{' && in_format_code == false) + { in_format_code = true; forward = format[i]; continue; } - if (format[i] == '}' && in_format_code) { + if (format[i] == '}' && in_format_code) + { in_format_code = false; after_colon = false; forward = format[i]; continue; } - if (in_format_code && !after_colon && isdigit(format[i])) { + if (in_format_code && !after_colon && isdigit(format[i])) + { arg_cnt = arg_cnt * 10 + (format[i] - '0'); } - if (format[i] == ':' && in_format_code == true) { + if (format[i] == ':' && in_format_code == true) + { after_colon = true; forward = format[i]; continue; } - if (in_format_code == true) { - if (format[i] == '{' && forward == '{') { + if (in_format_code == true) + { + if (format[i] == '{' && forward == '{') + { in_format_code = false; continue; } - if (after_colon == true) { - if (isalpha(format[i])) { - if (is_specifier_integer(format[i])) { - if (specifiers.is_long_long) { + if (after_colon == true) + { + if (isalpha(format[i])) + { + if (is_specifier_integer(format[i])) + { + if (specifiers.is_long_long) + { arguments[arg_cnt].type = mdr_long_long; arg_max = arg_cnt; arg_cnt = 0; } num += printf(buff, va_arg(args, int)); - } else if (is_specifier_float(format[i])) { + } + else if (is_specifier_float(format[i])) + { num += printf(buff, va_arg(args, double)); - } else if (format[i] == 'c') { + } + else if (format[i] == 'c') + { num += printf(buff, va_arg(args, int)); - } else if (format[i] == 's') { - } else if (format[i] == 'l') { - if (!specifiers.is_long) { + } + else if (format[i] == 's') + { + } + else if (format[i] == 'l') + { + if (!specifiers.is_long) + { specifiers.is_long = true; - } else if (!specifiers.is_long_long) { + } + else if (!specifiers.is_long_long) + { specifiers.is_long_long = true; - } else { + } + else + { perror("specifier ?"); } } @@ -163,82 +193,117 @@ int mdr_print(char* restrict format, ...) forward = format[i]; } } - for (int i = 0; i < arg_max; i++) { - if (arguments[i].type == mdr_int) { + for (int i = 0; i < arg_max; i++) + { + if (arguments[i].type == mdr_int) + { int value = va_arg(args, int); - byte* ptr = (byte*)&value; - for (int j = 0; j < 8; j++) { + byte *ptr = (byte *)&value; + for (int j = 0; j < 8; j++) + { arguments[arg_cnt].plain_value[j] = ptr[j]; } } } } - for (int i = 0; i < strlen(format); i++) { - if (format[i] == '{' && in_format_code == false) { + for (int i = 0; i < strlen(format); i++) + { + if (format[i] == '{' && in_format_code == false) + { in_format_code = true; forward = format[i]; continue; } - if (format[i] == '}' && in_format_code) { + if (format[i] == '}' && in_format_code) + { in_format_code = false; after_colon = false; forward = format[i]; continue; } - if (format[i] == ':' && in_format_code == true) { + if (format[i] == ':' && in_format_code == true) + { after_colon = true; forward = format[i]; continue; } - if (in_format_code == true) { - if (format[i] == '{' && forward == '{') { + if (in_format_code == true) + { + if (format[i] == '{' && forward == '{') + { in_format_code = false; putchar('{'); num += 1; continue; } - if (after_colon == true) { + if (after_colon == true) + { buff[buff_cnt] = format[i]; buff_cnt++; buff[buff_cnt] = '\0'; - if (isalpha(format[i])) { - if (is_specifier_integer(format[i])) { - if (is_long && is_long_long) { + if (isalpha(format[i])) + { + if (is_specifier_integer(format[i])) + { + if (is_long && is_long_long) + { num += printf(buff, va_arg(args, long long)); - } else if (is_long) { + } + else if (is_long) + { num += printf(buff, va_arg(args, long)); - } else { + } + else + { num += printf(buff, va_arg(args, int)); } is_long = false; is_long_long = false; clear_buff(buff, &buff_cnt); - } else if (is_specifier_float(format[i])) { - if (is_capital_long) { + } + else if (is_specifier_float(format[i])) + { + if (is_capital_long) + { num += printf(buff, va_arg(args, long double)); - } else { + } + else + { num += printf(buff, va_arg(args, double)); } clear_buff(buff, &buff_cnt); - } else if (format[i] == 'c') { + } + else if (format[i] == 'c') + { num += printf(buff, va_arg(args, int)); clear_buff(buff, &buff_cnt); - } else if (format[i] == 'l') { - if (!is_long) { + } + else if (format[i] == 'l') + { + if (!is_long) + { is_long = true; - } else if (!is_long_long) { + } + else if (!is_long_long) + { is_long_long = true; - } else { + } + else + { perror("Unknown Format Code"); } - } else if (format[i] == 'L') { + } + else if (format[i] == 'L') + { is_capital_long = true; } } } - } else { + } + else + { putchar(format[i]); num++; } diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\347\214\234\346\225\260\346\270\270\346\210\217.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\347\214\234\346\225\260\346\270\270\346\210\217.c" index 6afcfdd..3dded31 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\347\214\234\346\225\260\346\270\270\346\210\217.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\347\214\234\346\225\260\346\270\270\346\210\217.c" @@ -9,18 +9,24 @@ int main(void) { int secret = rand() % 100 + 1; - for (;;) { + for (;;) + { int guess; printf("Enter your guess: "); scanf("%d", &guess); - if (guess == secret) { + if (guess == secret) + { printf("You win!\n"); break; - } else if (guess > secret) { + } + else if (guess > secret) + { printf("Too high!\n"); - } else { + } + else + { printf("Too low!\n"); } } return 0; -} \ No newline at end of file +} diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\350\264\250\346\225\260\346\211\253\346\217\217.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\350\264\250\346\225\260\346\211\253\346\217\217.c" index 474d157..c88d9d0 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\350\264\250\346\225\260\346\211\253\346\217\217.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\347\273\203\344\271\240/unk_\350\264\250\346\225\260\346\211\253\346\217\217.c" @@ -9,7 +9,7 @@ int main(void) { if (num == t) { - printf("%d",num); + printf("%d", num); } if (num % t == 0) { @@ -17,4 +17,4 @@ int main(void) } } } -} \ No newline at end of file +} diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/10_\346\224\271\350\277\233\347\232\204BMI\346\265\213\350\257\225.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/10_\346\224\271\350\277\233\347\232\204BMI\346\265\213\350\257\225.c" index 2bae67f..c382d32 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/10_\346\224\271\350\277\233\347\232\204BMI\346\265\213\350\257\225.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/10_\346\224\271\350\277\233\347\232\204BMI\346\265\213\350\257\225.c" @@ -22,13 +22,20 @@ int main() // 判断健康状态 #ifndef AMAZING - if (bmi < 18.5) { + if (bmi < 18.5) + { printf("您的体重过轻。\n"); - } else if (bmi < 25) { + } + else if (bmi < 25) + { printf("您的体重正常。\n"); - } else if (bmi < 30) { + } + else if (bmi < 30) + { printf("您的体重过重。\n"); - } else { + } + else + { printf("您的体重肥胖。\n"); } #else diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/12_\347\256\200\346\230\223\350\256\241\347\256\227\345\231\250.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/12_\347\256\200\346\230\223\350\256\241\347\256\227\345\231\250.c" index be3348a..fc7f03e 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/12_\347\256\200\346\230\223\350\256\241\347\256\227\345\231\250.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/12_\347\256\200\346\230\223\350\256\241\347\256\227\345\231\250.c" @@ -19,7 +19,8 @@ int main() // 判断运算符是否有效 // 根据运算符进行计算 - switch (operator) { + switch (operator) + { case '+': result = add(num1, num2); break; @@ -31,7 +32,8 @@ int main() break; case '/': result = divide(num1, num2); - if (num2 == 0) { + if (num2 == 0) + { return 22; } break; @@ -66,7 +68,8 @@ double multiply(double a, double b) // 除法函数 double divide(double a, double b) { - if (b == 0) { + if (b == 0) + { perror("除数不能为0\n"); return 0.0; } diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/\350\264\250\345\233\240\346\225\260\345\210\206\350\247\243.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/\350\264\250\345\233\240\346\225\260\345\210\206\350\247\243.c" index 9e3737b..c63edf9 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/\350\264\250\345\233\240\346\225\260\345\210\206\350\247\243.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/\350\264\250\345\233\240\346\225\260\345\210\206\350\247\243.c" @@ -3,10 +3,12 @@ int main(void) { unsigned long long n, i; scanf("%llu", &n); - for (i = 2; n /= 2; ++i) { - for (; n % i == 0; n /= i) { + for (i = 2; n /= 2; ++i) + { + for (; n % i == 0; n /= i) + { printf("%llu\n", i); } } return 0; -} \ No newline at end of file +} diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/kheap.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/kheap.c" index d9c796a..895ae72 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/kheap.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/kheap.c" @@ -5,15 +5,18 @@ header_t *head = NULL, *tail = NULL; // 内存块链表 extern page_directory_t *current_directory; extern uint32_t end; // declared in linker.ld -static uint32_t placement_address = (uint32_t) &end; +static uint32_t placement_address = (uint32_t)&end; void *program_break, *program_break_end; extern struct task_struct *current; -uint32_t memory_usage(){ +uint32_t memory_usage() +{ header_t *curr = head; uint32_t size; - while (curr) { - if(!curr->s.is_free){ + while (curr) + { + if (!curr->s.is_free) + { size += curr->s.size; } curr = curr->s.next; @@ -21,58 +24,72 @@ uint32_t memory_usage(){ return size; } -uint32_t kmalloc_i_ap(uint32_t size, uint32_t *phys){ - if ((placement_address & 0x00000FFF)) { +uint32_t kmalloc_i_ap(uint32_t size, uint32_t *phys) +{ + if ((placement_address & 0x00000FFF)) + { placement_address &= 0xFFFFF000; placement_address += 0x1000; } - if (phys) *phys = placement_address; + if (phys) + *phys = placement_address; uint32_t tmp = placement_address; placement_address += size; return tmp; } -static uint32_t kmalloc_int(size_t sz, uint32_t align, uint32_t *phys) { - if (program_break) { +static uint32_t kmalloc_int(size_t sz, uint32_t align, uint32_t *phys) +{ + if (program_break) + { // 有内存堆 void *addr = alloc(sz); // 直接malloc,align丢掉了 - if (phys) { + if (phys) + { // 需要物理地址,先找到对应页 - page_t *page = get_page((uint32_t) addr, 0, current_directory,false); - *phys = page->frame * 0x1000 + ((uint32_t) addr & 0x00000FFF); + page_t *page = get_page((uint32_t)addr, 0, current_directory, false); + *phys = page->frame * 0x1000 + ((uint32_t)addr & 0x00000FFF); } - return (uint32_t) addr; + return (uint32_t)addr; } - if (align == 1 && (placement_address & 0x00000FFF)) { + if (align == 1 && (placement_address & 0x00000FFF)) + { placement_address &= 0xFFFFF000; placement_address += 0x1000; } - if (phys) *phys = placement_address; + if (phys) + *phys = placement_address; uint32_t tmp = placement_address; placement_address += sz; return tmp; } -uint32_t kmalloc_a(uint32_t size) { +uint32_t kmalloc_a(uint32_t size) +{ return kmalloc_int(size, 1, 0); } -uint32_t kmalloc_p(uint32_t size, uint32_t *phys) { +uint32_t kmalloc_p(uint32_t size, uint32_t *phys) +{ return kmalloc_int(size, 0, phys); } -uint32_t kmalloc_ap(uint32_t size, uint32_t *phys) { +uint32_t kmalloc_ap(uint32_t size, uint32_t *phys) +{ return kmalloc_int(size, 1, phys); } -uint32_t kmalloc(uint32_t size) { +uint32_t kmalloc(uint32_t size) +{ return kmalloc_int(size, 0, 0); } -void *ksbrk(int incr) { - if (program_break == 0 || program_break + incr >= program_break_end) return (void *) -1; +void *ksbrk(int incr) +{ + if (program_break == 0 || program_break + incr >= program_break_end) + return (void *)-1; void *prev_break = program_break; program_break += incr; @@ -80,48 +97,64 @@ void *ksbrk(int incr) { } // 寻找一个符合条件的指定大小的空闲内存块 -static header_t *get_free_block(size_t size) { +static header_t *get_free_block(size_t size) +{ header_t *curr = head; - while (curr) { - if (curr->s.is_free && curr->s.size >= size) return curr; + while (curr) + { + if (curr->s.is_free && curr->s.size >= size) + return curr; curr = curr->s.next; } return NULL; } -void *alloc(size_t size) { +void *alloc(size_t size) +{ uint32_t total_size; void *block; header_t *header; - if (!size) return NULL; + if (!size) + return NULL; header = get_free_block(size); - if (header) { + if (header) + { header->s.is_free = 0; - return (void *) (header + 1); + return (void *)(header + 1); } total_size = sizeof(header_t) + size; block = ksbrk(total_size); - if (block == (void *) -1) return NULL; + if (block == (void *)-1) + return NULL; header = block; header->s.size = size; header->s.is_free = 0; header->s.next = NULL; - if (!head) head = header; - if (tail) tail->s.next = header; + if (!head) + head = header; + if (tail) + tail->s.next = header; tail = header; - return (void *) (header + 1); + return (void *)(header + 1); } -void kfree(void *block) { +void kfree(void *block) +{ header_t *header, *tmp; - if (!block) return; - header = (header_t *) block - 1; - if ((char *) block + header->s.size == program_break) { - if (head == tail) head = tail = NULL; - else { + if (!block) + return; + header = (header_t *)block - 1; + if ((char *)block + header->s.size == program_break) + { + if (head == tail) + head = tail = NULL; + else + { tmp = head; - while (tmp) { - if (tmp->s.next == tail) { + while (tmp) + { + if (tmp->s.next == tail) + { tmp->s.next = NULL; tail = tmp; } diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/memory.c" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/memory.c" index af7d092..1f5864e 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/memory.c" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/memory.c" @@ -1,63 +1,75 @@ #include "../include/memory.h" -void memclean(char *s, int len) { +void memclean(char *s, int len) +{ // 清理某个内存区域(全部置0) int i; - for (i = 0; i != len; i++) { + for (i = 0; i != len; i++) + { s[i] = 0; } return; } -void* memcpy(void* s, const void* ct, size_t n) { +void *memcpy(void *s, const void *ct, size_t n) +{ if (NULL == s || NULL == ct || n <= 0) return NULL; while (n--) - *(char*)s++ = *(char*)ct++; + *(char *)s++ = *(char *)ct++; return s; } -int memcmp(const void *a_, const void *b_, uint32_t size) { +int memcmp(const void *a_, const void *b_, uint32_t size) +{ const char *a = a_; const char *b = b_; - while (size-- > 0) { - if (*a != *b) return *a > *b ? 1 : -1; + while (size-- > 0) + { + if (*a != *b) + return *a > *b ? 1 : -1; a++, b++; } return 0; } -void *memset(void *s, int c, size_t n) { +void *memset(void *s, int c, size_t n) +{ unsigned char *p = s; while (n-- > 0) *p++ = c; return s; } -void *memmove(void *dest, const void *src, size_t num) { +void *memmove(void *dest, const void *src, size_t num) +{ void *ret = dest; - if (dest < src) { - while (num--)//前->后 + if (dest < src) + { + while (num--) // 前->后 { - *(char *) dest = *(char *) src; - dest = (char *) dest + 1; - src = (char *) src + 1; + *(char *)dest = *(char *)src; + dest = (char *)dest + 1; + src = (char *)src + 1; } - } else { - while (num--)//后->前 + } + else + { + while (num--) // 后->前 { - *((char *) dest + num) = *((char *) src + num); + *((char *)dest + num) = *((char *)src + num); } } return ret; } - -void *realloc(void *ptr, uint32_t size) { +void *realloc(void *ptr, uint32_t size) +{ void *new = kmalloc(size); - if (ptr) { + if (ptr) + { memcpy(new, ptr, *(int *)((int)ptr - 4)); kfree(ptr); } return new; -} \ No newline at end of file +} diff --git "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/printf.h" "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/printf.h" index 88d1580..cef5cde 100644 --- "a/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/printf.h" +++ "b/\346\225\231\347\250\213/\347\244\272\344\276\213\344\273\243\347\240\201/\351\241\271\347\233\256/mdrOS/printf.h" @@ -14,8 +14,8 @@ void print(char *message); void printk(const char *formet, ...); void putchar(char c); void logk(char *message); -void logkf(char *formet,...); +void logkf(char *formet, ...); void screen_clear(); -void klogf(bool isok,char* fmt,...); +void klogf(bool isok, char *fmt, ...); -#endif //CRASHPOWEROS_PRINTF_H +#endif // CRASHPOWEROS_PRINTF_H From 917973a98b676b3f08ff24433df2882bead41293 Mon Sep 17 00:00:00 2001 From: LY-Xiang Date: Fri, 23 Aug 2024 13:08:41 +0800 Subject: [PATCH 3/7] format fix --- .../\351\241\271\347\233\256/MdrOS/build.md" | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" index dba27d2..6fdf3ed 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" @@ -51,34 +51,34 @@ ENTRY(_start) SECTIONS { - . = 2M; - - .text BLOCK(4K) : ALIGN(4K) - { - code = .; _code = .; __code = .; - *(.multiboot) - *(.text) - } - - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } - - .data BLOCK(4K) : ALIGN(4K) - { - data = .; _data = .; __data = .; - *(.data) - } - - .bss BLOCK(4K) : ALIGN(4K) - { - bss = .; _bss = .; __bss = .; - *(COMMON) - *(.bss) - } - - end = .; _end = .; __end = .; + . = 2M; + + .text BLOCK(4K) : ALIGN(4K) + { + code = .; _code = .; __code = .; + *(.multiboot) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + data = .; _data = .; __data = .; + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + bss = .; _bss = .; __bss = .; + *(COMMON) + *(.bss) + } + + end = .; _end = .; __end = .; } ``` @@ -116,10 +116,10 @@ obj_dos := $(out_path_src)源文件名.obj ... #填写你所有的源文件对 default : $(obj_dos) $(out_path_src)%.o : %.c Makefile #C源文件构建 - $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o + $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o $(out_path_src)%.obj : %.asm Makefile - nasm -f elf $*.asm -o $(out_path_src)$*.obj + nasm -f elf $*.asm -o $(out_path_src)$*.obj ``` ### Python From d94a42724b46324647da124ca83373122e845d8c Mon Sep 17 00:00:00 2001 From: LY-Xiang Date: Fri, 23 Aug 2024 13:08:53 +0800 Subject: [PATCH 4/7] format fix --- .../\351\241\271\347\233\256/MdrOS/build.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" index 6fdf3ed..564edab 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\351\241\271\347\233\256/MdrOS/build.md" @@ -116,10 +116,10 @@ obj_dos := $(out_path_src)源文件名.obj ... #填写你所有的源文件对 default : $(obj_dos) $(out_path_src)%.o : %.c Makefile #C源文件构建 - $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o + $(gcc) -I$(incpath_src) -nostdinc -nolibc -nostdlib -fno-builtin -ffreestanding -fno-stack-protector -Qn -fno-pic -fno-pie -fno-asynchronous-unwind-tables -mpreferred-stack-boundary=2 -fomit-frame-pointer -O0 -finput-charset=UTF-8 -fexec-charset=GB2312 -mno-mmx -mno-sse -mfpmath=387 -w -c $*.c -o $(out_path_src)$*.o $(out_path_src)%.obj : %.asm Makefile - nasm -f elf $*.asm -o $(out_path_src)$*.obj + nasm -f elf $*.asm -o $(out_path_src)$*.obj ``` ### Python From 701f8efc919f2f321c3e757e9a8b2c3d57d1bed9 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Fri, 23 Aug 2024 13:19:27 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E8=A1=A8=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1_\347\272\277\346\200\247\350\241\250.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" index f5f331e..bd0f2be 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" @@ -25,7 +25,7 @@ ### 2.1 基本概念 -1. 物理结构,元素存储在一段 **逻辑地址连续** 的存储单元上 +1. 元素存储在一段 **逻辑地址连续** 的存储单元上, 连续保证了可以用指针偏移的方式访问 2. 通常使用数组实现 3. 因为数组下标从 **0** 开始,所以 **逻辑下标** 为 **1** 的元素存储在数组下标为 **0** 的位置上,这个下标称为此元素的 **物理下标** 4. 在顺序表中,通常情况下,**物理下标** = **逻辑下标-1** From e293c9a6a2b2e05635c31f9b46cb966a22a098a9 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Fri, 23 Aug 2024 13:31:40 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BA=BF=E6=80=A7?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E5=AF=B9=E7=89=A9=E7=90=86=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../1_\347\272\277\346\200\247\350\241\250.md" | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e06819d..db224d9 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ int main(int argc, char* argv[]){ + **菲露露** ([GitHub - LovelyLavender4](https://github.com/lovelylavender4)) + **XIAOYI12** ([GitHub - xiaoyi1212](https://github.com/xiaoyi1212)) + **WHITE TREE**([GitHub - VinbeWan](https://github.com/VinbeWan)) ++ **A4-Tacks**([GitHub - A4-Tacks](https://github.com/A4-Tacks)) ### 组织 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" index bd0f2be..5e0ee51 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\346\225\260\346\215\256\347\273\223\346\236\204/1_\347\272\277\346\200\247\350\241\250.md" @@ -5,11 +5,10 @@ ### 1.1 基本概念 1. 定义:一种逻辑结构,表示 N 个相同类型元素的有限序列 -2. 逻辑结构中连续,物理结构上不一定连续 -3. 常见的线性表:顺序表,栈和队列,链表,字符串等 -4. 线性表的数据集合可以写作 $\{a_1,a_2,a_3,...,a_n\}$,其中 $n$ 为线性表的 **长度** (length),$1,2,3,...,n$ 称为线性表中各个元素的 **逻辑下标** -5. 在线性表中,除最后一个元素(这个元素称为 **终端节点** 之外,每一个元素 $a_i$ 都有一个元素作为他的 **后继**,记作 $\mathrm{next}(a_i)$ -6. 在线性表中,除第一个元素(这个元素称为 **开始节点**)之外,每一个元素 $a_i$ 都有一个元素作为他的 **前驱**,记作 $\mathrm{prev}(a_i)$ +2. 常见的线性表:顺序表,栈和队列,链表,字符串等 +3. 线性表的数据集合可以写作 $\{a_1,a_2,a_3,...,a_n\}$,其中 $n$ 为线性表的 **长度** (length),$1,2,3,...,n$ 称为线性表中各个元素的 **逻辑下标** +4. 在线性表中,除最后一个元素(这个元素称为 **终端节点** 之外,每一个元素 $a_i$ 都有一个元素作为他的 **后继**,记作 $\mathrm{next}(a_i)$ +5. 在线性表中,除第一个元素(这个元素称为 **开始节点**)之外,每一个元素 $a_i$ 都有一个元素作为他的 **前驱**,记作 $\mathrm{prev}(a_i)$ ### 1.2 基本操作 From c0fc7f357edc7da63ed54d1c562f85c5b2dc7abb Mon Sep 17 00:00:00 2001 From: Minsecrus <2972853299@qq.com> Date: Fri, 23 Aug 2024 16:35:57 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++-- .../\346\200\273\347\272\262.md" | 3 +- ...64\345\244\215\346\235\202\345\272\246.md" | 8 +-- ...14\351\200\222\345\275\222\345\274\217.md" | 10 +-- ..._C\346\240\207\345\207\206\345\272\223.md" | 1 + ..._C\345\244\215\346\225\260\345\272\223.md" | 0 ...45\350\276\223\345\207\272\345\272\223.md" | 1 + ...345\255\227\347\254\246\344\270\262API.md" | 0 ...06\345\272\223\346\211\251\345\261\225.md" | 0 ...5\347\232\204C\347\250\213\345\272\217.md" | 10 ++- .../2_2_\346\263\250\351\207\212.md" | 0 ...04\345\244\204\347\220\206\345\231\250.md" | 2 +- ...1\350\261\241_\345\210\235\346\255\245.md" | 4 +- .../3_1_\350\241\214\344\270\272.md" | 0 ...6_\350\241\250\350\276\276\345\274\217.md" | 6 +- ...63\344\272\216\350\277\233\345\210\266.md" | 62 ++++++++++++++++--- .../\350\256\241\347\256\227\346\234\272.md" | 2 +- 17 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223.md" rename "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" => "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" (100%) create mode 100644 "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\350\276\223\345\205\245\350\276\223\345\207\272\345\272\223.md" rename "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" => "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" (100%) rename "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" => "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" (100%) rename "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" => "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_1_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" (91%) rename "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\346\263\250\351\207\212.md" => "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_2_\346\263\250\351\207\212.md" (100%) create mode 100644 "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_\345\237\272\346\234\254\346\246\202\345\277\265/3_1_\350\241\214\344\270\272.md" diff --git a/README.md b/README.md index db224d9..2660da8 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ int main(int argc, char* argv[]){ 5. 段落和段落之间有一个空行;只换行不换段落,无空行,在前一行结尾加两个空格; 6. **强调** 用 `** **` 标识,*次强调* 用 `* *` 标识,`代码块` 用 `` ` ` `` 标识; 7. 引文和注释用 `>` 标识;书名和文章名用 `*** ***` 标识; -8. `*** ***` `** **` `* *` `` ` ` `` 前后 **各空一个空格**,但中文标点前后无需加空格; +8. `*** ***` `** **` `* *` `` ` ` `` `$ $` 前后 **各空一个空格**,但中文标点前后无需加空格; 9. 中西文字符,或者中文和数字之间加一个空格; 10. 在中文上下文中用全角标点,比如全角小括号,全角冒号等; 11. 要正确使用标点符号,分清 **顿号**、**逗号**、**分号** 和 **句号**,尤其避免一逗到底; 12. 分清 **的地得** 和 **他她它祂怹** -13. 仅在必要时使用 **数量词**(尤其是 **一个**)~~你是一个一个一个~~ +13. 仅在必要时使用 **数量词**(尤其警惕 **一个** 的不恰当使用)~~你是一个一个一个~~ 14. 在 **术语** (Terminology) 首次出现的时候在 **半角小括号** 内给出 **对应的外来语**,同时给出 **首字母缩略语** (Acronym)。这些外来语通常对应 **概念** (Concept) 的原文 ,希望有助于读者明确分辨词语的含义: 1. 为减少读者的记忆负担,下文分情况使用 **术语的汉语表述** 和 **首字母缩略语**:初始章节以前者为主,进阶章节以后者为主 2. 外来语和缩略语可能视情况在不同章节多次出现 @@ -57,7 +57,7 @@ int main(int argc, char* argv[]){ 5. 大部分外来语单词摘自 [维基百科](https://zh.wikipedia.org) 和 [C++ 参考手册](https://en.cppreference.com/); 15. **专有名词** 需 **大写**; 16. 图片统一放在 `/images/` 目录下,并采用 **绝对路径** 引入: - 1. 截图统一采用 **PNG** 格式,命名为三位数字,如:`001.png`; + 1. 截图统一采用 **PNG** 格式,命名为三位数字,如:`001.png`; 2. 拍照统一采用 **JPEG** 格式,命名为不带前导零的数字,如:`1.jpg`; 17. 在每篇文档结尾写出引用内容的出处; 18. 语言风格: @@ -72,7 +72,7 @@ int main(int argc, char* argv[]){ 1. 如果是项目代码,需要构建系统完成编译运行,需将必要的相关文件放入对应目录,例如 `CMakeLists.txt` 和 `xmake.lua` 等; 2. 源文件后缀名为 `.c`,头文件后缀名为 `.h`; 3. 标识符采用惯例命名,不允许使用拼音; -4. `if` `else` `for` `while` 必须跟随一条 **复合语句**。 +4. `if` `else` `for` `while` 必须跟随 **复合语句**。 ## 对预期读者的要求 @@ -95,8 +95,9 @@ int main(int argc, char* argv[]){ + **FHU-yezi** ([GitHub - FHU-yezi](https://github.com/FHU-yezi)) + **菲露露** ([GitHub - LovelyLavender4](https://github.com/lovelylavender4)) + **XIAOYI12** ([GitHub - xiaoyi1212](https://github.com/xiaoyi1212)) -+ **WHITE TREE**([GitHub - VinbeWan](https://github.com/VinbeWan)) -+ **A4-Tacks**([GitHub - A4-Tacks](https://github.com/A4-Tacks)) ++ **WHITE TREE** ([GitHub - VinbeWan](https://github.com/VinbeWan)) ++ **min0911Y** ([GitHub - min0911Y](https://github.com/min0911Y)) ++ **A4-Tacks** ([GitHub - A4-Tacks](https://github.com/A4-Tacks)) ### 组织 @@ -121,3 +122,4 @@ int main(int argc, char* argv[]){ + ***算法导论*** (ISBN 978-7-111-40701-0) + [***Let's Build a Simple Database***](https://cstack.github.io/db_tutorial/) + [***pldocs***](https://github.com/FrankHB/pl-docs/blob/master/zh-CN) ++ ***陶哲轩实分析*** (ISBN 978-7-115-48025-5) diff --git "a/\346\225\231\347\250\213/\346\200\273\347\272\262.md" "b/\346\225\231\347\250\213/\346\200\273\347\272\262.md" index 7082966..70a03fe 100644 --- "a/\346\225\231\347\250\213/\346\200\273\347\272\262.md" +++ "b/\346\225\231\347\250\213/\346\200\273\347\272\262.md" @@ -15,7 +15,8 @@ 5. **字符串字面量** 3. **基本概念** 1. **行为** - 2. **翻译阶段** + 2. **翻译单元** + 3. **翻译阶段** 4. **表达式** 1. [**运算符** **表达式**](/教程/正文/语法和标准库/7_运算符_表达式.md) 概述 2. [**位操作**](/教程/正文/语法和标准库/34_位操作.md) diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/3_\347\256\227\346\263\225\347\232\204\346\227\266\351\227\264\345\222\214\347\251\272\351\227\264\345\244\215\346\235\202\345\272\246.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/3_\347\256\227\346\263\225\347\232\204\346\227\266\351\227\264\345\222\214\347\251\272\351\227\264\345\244\215\346\235\202\345\272\246.md" index 9014dec..e994291 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/3_\347\256\227\346\263\225\347\232\204\346\227\266\351\227\264\345\222\214\347\251\272\351\227\264\345\244\215\346\235\202\345\272\246.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/3_\347\256\227\346\263\225\347\232\204\346\227\266\351\227\264\345\222\214\347\251\272\351\227\264\345\244\215\346\235\202\345\272\246.md" @@ -1,13 +1,13 @@ # 时间复杂度 -> 经常有人疑惑 $\Theta(n)=\lg n$ 中 lg 的底数是多少(包括过去的mdr) -> 实际上对数的底数是几 **无关紧要**,因为不同底数的对数之间只差一个 **常数**,而计算时间复杂度的时候 **不考虑** 常数 +> 经常有人疑惑 $\Theta(n)=\lg n$ 中 lg 的底数是多少; +> 对数的底数是几 **无关紧要**,因为根据 **换底公式**,不同底数的对数之间只差一个 **常数**,而计算时间复杂度的时候 **不考虑** 常数 ## 1. 含义 1. 算法在特定输入下的 **运行时间** 指执行的基本操作数或步数 2. **时间复杂度** 是定性描述该算法运行时间的函数,可以用来估计该算法的运行时间 -3. 当输入规模足够大的时候,这个函数的低阶项和最高阶项的常数项对函数值的影响相较于最高阶项指数对函数值的影响来说可以 **忽略不计**,也就是说只对运行时间的 +3. 当输入规模足够大的时候,这个函数的低阶项和最高阶项的常数项对函数值的影响相较于最高阶项指数对函数值的影响来说可以 **忽略不计**,也就是说只对运行时间的 **次数** 做描述 ## 2. 渐进记号 @@ -71,7 +71,7 @@ ### 1. 定义 -一个算法的 **空间复杂度** 指该算法 **执行过程中** 所需要消耗的存储空间资源 +算法的 **空间复杂度** 指该算法 **执行过程中** 所需要消耗的存储空间资源 > 注:**不要** 把输入数据所占的存储空间包括在内 ### 2. 表示方法 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225\345\222\214\351\200\222\345\275\222\345\274\217.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225\345\222\214\351\200\222\345\275\222\345\274\217.md" index b9a80bf..71a1cff 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225\345\222\214\351\200\222\345\275\222\345\274\217.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\346\225\260\346\215\256\347\273\223\346\236\204\344\270\216\347\256\227\346\263\225/\347\256\227\346\263\225/4_\345\210\206\346\262\273\346\263\225\345\222\214\351\200\222\345\275\222\345\274\217.md" @@ -178,16 +178,16 @@ 1. 猜测解的形式 2. 用 [**数学归纳法**](https://zh.wikipedia.org/wiki/%E6%95%B0%E5%AD%A6%E5%BD%92%E7%BA%B3%E6%B3%95) 求出解中的常数,并验证解的正确性 -示例:对于递归式 $T(n)=2T\lfloor n/2\rfloor+n$ : +示例:对于递归式 $T(n)=2T\lfloor \frac{n}{2}\rfloor+n$ : 1. 猜测解的形式:$T(n)=O(n\lg n)$ 2. 用数学归纳法证明该式子,即证明对于足够大的常数 $c$,有 $T(n)\le cn\lg n$: - 1. 假设对 $\lfloor n/2\rfloor$ 成立: + 1. 假设对 $\lfloor \frac{n}{2}\rfloor$ 成立: 代入,得 $$ \begin{aligned} - T(n) & \le 2(c\lfloor n/2\rfloor \lg\lfloor n/2\rfloor)+n\\ - & \le cn\lg(n/2)+n\\ + T(n) & \le 2(c\lfloor \frac{n}{2}\rfloor \lg\lfloor \frac{n}{2}\rfloor)+n\\ + & \le cn\lg(\frac{n}{2})+n\\ & =cn\lg n-cn\lg 2+n\\ & =cn\lg n-cn+n\\ & \le cn\lg n @@ -198,7 +198,7 @@ 2. 证明对于 $n=2$ 和 $n=3$ 成立: 当 $n=2$ 时,$T(2)=2T(1)+2=4$,此时可以找到一个足够大的 $c$(比如取 2),使 $T(2)\le 2c\lg 2$ 成立。 同理可证 $n=3$ 成立。 - 3. 由上面两步,我们证明了(为什么?)$T(n)=2T\lfloor n/2\rfloor+n$ 的上界是 $O(n\lg n)$。 + 3. 由上面两步,因为在正整数 $n$ 只有等于 2 或 3 时,$\lfloor\frac{n}{2}\rfloor$ 才等于 1,所以我们证明了(为什么?)$T(n)=2T\lfloor n/2\rfloor+n$ 的上界是 $O(n\lg n)$。 有时复杂的递归式可以通过 **换元法** 化简。 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223.md" new file mode 100644 index 0000000..b19e69c --- /dev/null +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223.md" @@ -0,0 +1 @@ +# C 标准库 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" similarity index 100% rename from "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" rename to "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\345\244\215\346\225\260\345\272\223.md" diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\350\276\223\345\205\245\350\276\223\345\207\272\345\272\223.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\350\276\223\345\205\245\350\276\223\345\207\272\345\272\223.md" new file mode 100644 index 0000000..c3d5d40 --- /dev/null +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_C\350\276\223\345\205\245\350\276\223\345\207\272\345\272\223.md" @@ -0,0 +1 @@ +# C 输入输出库 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" similarity index 100% rename from "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" rename to "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\345\255\227\347\254\246\344\270\262API.md" diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" similarity index 100% rename from "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" rename to "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/24_C\346\240\207\345\207\206\345\272\223/unk_\346\240\207\345\207\206\345\272\223\346\211\251\345\261\225.md" diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_1_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" similarity index 91% rename from "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" rename to "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_1_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" index 00e3cea..3a827f1 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_1_\344\270\200\344\270\252\347\256\200\345\215\225\347\232\204C\347\250\213\345\272\217.md" @@ -10,7 +10,7 @@ int main(void) { // 在屏幕上输出一行字 - printf("hello world\n"); + puts("hello world"); return 0; } ``` @@ -56,15 +56,13 @@ int main(void) { 2. 标准规定的:`int main(int argc, char* argv[])` 3. 很多编译器实现的:`int main(int argc, char* argv[], char* envp[])` -## 5. `printf` 函数 +## 5. `puts` 函数 1. 这是标准库 **stdio.h** 里面提供的函数 2. 用于在屏幕上打印内容 -3. f 是 **format** 的意思 ## 6. 返回值 (return value, RV) -1. return 的东西就是函数的返回值 +1. return 的东西是函数的返回值 2. main 函数的返回值为 0,说明程序正常退出 -3. 实际上 `return 0` 可以不写,因为主函数正常执行到末尾 **如同返回 0**; - 但出于代码规范,建议还是写一下 +3. 实际上 `return 0` 可以不写,因为主函数正常执行到末尾 **如同返回 0**。 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\346\263\250\351\207\212.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_2_\346\263\250\351\207\212.md" similarity index 100% rename from "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\346\263\250\351\207\212.md" rename to "\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/2_\345\210\235\350\257\206C/2_2_\346\263\250\351\207\212.md" diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/37_\351\242\204\345\244\204\347\220\206\345\231\250.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/37_\351\242\204\345\244\204\347\220\206\345\231\250.md" index 89013d4..aaa7cf3 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/37_\351\242\204\345\244\204\347\220\206\345\231\250.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/37_\351\242\204\345\244\204\347\220\206\345\231\250.md" @@ -37,7 +37,7 @@ } ``` - `max(1,2)`会被替换成`(((1)>(2))?(1):(2))` + `max(1,2)` 会被替换成 `(((1)>(2))?(1):(2))` 因为宏是文本的替换,因此在替换过程中可能会导致一些运算符优先级问题,如下: ```c diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_C\345\257\271\350\261\241_\345\210\235\346\255\245.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_C\345\257\271\350\261\241_\345\210\235\346\255\245.md" index 7cdec87..75c07be 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_C\345\257\271\350\261\241_\345\210\235\346\255\245.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_C\345\257\271\350\261\241_\345\210\235\346\255\245.md" @@ -53,8 +53,8 @@ int a = {}; // C23 起 1. **类型**:`_Bool(bool)` `char` `double` `float` `int` `long` `short` `signed` `unsigned` `void` `_Complex` `_Decimal32` `_Decimal64` `_Decimal128` `_Imaginary` `_BigInt` 2. **指定符和限定符**:`inline` `restrict` `_Alignas(alignas)` `_Atomic` `_Generic` 3. **常量**:`true` `false` `nullptr` -4. **控制语句**相关:`break` `case` `continue` `default` `do` `else` `for` `goto` `if` `return` `switch` `while` -5. **存储类**说明符:`auto` `extern` `register` `static` `constexpr` `auto` `_Thread_local(thread_local)` +4. **控制语句** 相关:`break` `case` `continue` `default` `do` `else` `for` `goto` `if` `return` `switch` `while` +5. **存储类** 说明符:`auto` `extern` `register` `static` `constexpr` `auto` `_Thread_local(thread_local)` 6. **运算符**:`sizeof` `typeof` `typeof_uneqal` `_Alignof(alignof)` 7. **类型的声明**:`enum` `struct` `union` 8. **其他**:`_Static_assert(static_assert)` `typedef` diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_\345\237\272\346\234\254\346\246\202\345\277\265/3_1_\350\241\214\344\270\272.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/3_\345\237\272\346\234\254\346\246\202\345\277\265/3_1_\350\241\214\344\270\272.md" new file mode 100644 index 0000000..e69de29 diff --git "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/7_\350\277\220\347\256\227\347\254\246_\350\241\250\350\276\276\345\274\217.md" "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/7_\350\277\220\347\256\227\347\254\246_\350\241\250\350\276\276\345\274\217.md" index 0c32b41..b73bdb7 100644 --- "a/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/7_\350\277\220\347\256\227\347\254\246_\350\241\250\350\276\276\345\274\217.md" +++ "b/\346\225\231\347\250\213/\346\255\243\346\226\207/\350\257\255\346\263\225\345\222\214\346\240\207\345\207\206\345\272\223/7_\350\277\220\347\256\227\347\254\246_\350\241\250\350\276\276\345\274\217.md" @@ -24,14 +24,14 @@ C 中有 30 多种运算符,此章节只介绍一部分,并且只介绍它 ### 2.1 操作数 -对于一个运算符来说,需要传入的变量叫做 **操作数**,需要操作数数量为 **n** 的运算符称为 **n 元运算符** +对于一个运算符来说,需要传入的对象叫做 **操作数**,需要操作数数量为 **n** 的运算符称为 **n 元运算符** ### 2.2 运算符类型 #### 2.2.1 赋值运算符 `=` -C 中的 `=` 不表示 ~~等于~~ ,而表示 **赋值** -例如 `a = 3` 把 **3** 这个值赋给 `a` 这个变量 +C 中的 `=` 表示 **赋值** +例如 `a = 3` 把 **3** 这个值赋给 `a` 这个对象 #### 2.2.2 比较运算符 `==` `!=` `>` `<` `>=` `<=` diff --git "a/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" "b/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" index d19b58c..686f52d 100644 --- "a/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" +++ "b/\346\225\231\347\250\213/\347\225\252\345\244\226/77_\345\205\263\344\272\216\350\277\233\345\210\266.md" @@ -4,7 +4,7 @@ 我们通常都是基于数字10来表示数字,比如2157,千位为2、百位为1、十位为5、个位为7,由此,我们可以得出一个等式 -```C +```txt 2157 == 2 * 10^3 + 1 * 10^2 + 5 * 10^1 + 7 * 10^0 ``` @@ -14,15 +14,63 @@ 它使用2的幂而不是10的幂。以2为基底表示的数统称为 **二进制数** ( _binary number_ ), 二进制中的2和十进制中的10作用一样,都是基数,而2的幂则相当于十进制中的10的幂。例如: -```C +```txt 1011 == 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 ``` -## 1. 各种进制的字面量表示 +## 2. 数学中的十进制 + +> 本节中,我们假设自然数存在且满足皮亚诺公理。 + +1. 定义 **数字**:数字指 `0` `1` `2` `3` `4` `5` `6` `7` `8` `9` 这十个符号其中的任意一个。 + 把这些数字分别和某个自然数对应(++表示后继数): + + $0\equiv 0$ + + $1\equiv 0++$ + + $2\equiv 1++$ + + $3\equiv 2++$ + + $4\equiv 3++$ + + $5\equiv 4++$ + + $6\equiv 5++$ + + $7\equiv 6++$ + + $8\equiv 7++$ + + $9\equiv 8++$ +2. 定义 $十=9++$,避免循环论证。 +3. 定义 **十进制正整数**:十进制正整数指由数字组成的字符串 $a_na_{n-1}\dots a_0$,其中 $n$ 是一个自然数,并且数字 $a_n$ 不是 $0$。 + 十进制正整数等同于某个正整数: + $$a_na_{n-1}\dots a_0=\sum^n_{i=0}a_i\times 十^i$$ + 显然: + $$10=0\times 十^0+1\times 十^1=十$$ +4. 十进制表示的唯一性和存在性,即每一个正整数 $m$ 都恰好等于一个十进制正整数: + 1. 存在性,即每一个正整数 $m$ 都至少等于一个十进制正整数。 + 运用数学归纳法,假设对于所有正整数 $m'm$$ + 这与 $a_n\dots a_0=m$ 矛盾。 + 2. 当 $m \ge 十$ 时: + 可得 $m=s\times 十+r$,其中 $s$ 是正整数,$r \in \{1,2,3,4,5,6,7,8,9\}$。 + 由于 $s **字面量 (Literal)** 是指直接出现在程序中的数据,比如 10、3.14、'a' 等。 -### 1.1 **二进制** +### 3.1 **二进制** 二进制字面量以 `0b` 或 `0B` 开头,后面跟着二进制数字(0 和 1)。例如: @@ -30,7 +78,7 @@ int binary = 0b1010; // 二进制 1010,十进制 10 ``` -### 1.2 **八进制** +### 3.2 **八进制** 八进制字面量以 `0` 开头,后面跟着八进制数字(0-7)。例如: @@ -56,7 +104,7 @@ int octal = 012; // 八进制 12,十进制 10 例如:八进制值 `012` 对应的二进制值是 `000001010` ;八进制值 `077` 对应的二进制值是 `000111111` 。 -### 1.3 **十进制** +### 3.3 **十进制** 十进制字面量是默认的表示方法,不需要前缀。例如: @@ -64,7 +112,7 @@ int octal = 012; // 八进制 12,十进制 10 int decimal = 10; // 十进制 10 ``` -### 1.4 **十六进制** +### 3.4 **十六进制** 十六进制一共有16个表示数字 `0 ~ 15` ,但是由于没有单独的数 ( _digit_ ,即 `0~9` 这样的单独数字) 来表示 `10 ~ 15` , 所以我们用字母 `A ~ F` ( `a ~ f` )来表示。 diff --git "a/\346\235\202\351\241\271/\345\267\245\345\205\267\345\222\214\347\216\257\345\242\203/\345\267\245\345\205\267/\350\256\241\347\256\227\346\234\272.md" "b/\346\235\202\351\241\271/\345\267\245\345\205\267\345\222\214\347\216\257\345\242\203/\345\267\245\345\205\267/\350\256\241\347\256\227\346\234\272.md" index 65e8c40..119fa1c 100644 --- "a/\346\235\202\351\241\271/\345\267\245\345\205\267\345\222\214\347\216\257\345\242\203/\345\267\245\345\205\267/\350\256\241\347\256\227\346\234\272.md" +++ "b/\346\235\202\351\241\271/\345\267\245\345\205\267\345\222\214\347\216\257\345\242\203/\345\267\245\345\205\267/\350\256\241\347\256\227\346\234\272.md" @@ -36,4 +36,4 @@ 3. 如果输入 **powershell**,则会打开 PowerShell ![打开 powershell](/images/工具/计算机/008.png) 3. 在命令行中点击上下箭头,可以切换到历史命令,方便再次执行 - 4. 有一些工具可以让 powershell 拥有更好看的界面,例如 **Oh-My-Posh** 和 [**Starship**](https://starship.rs/zh-CN/guide/) + 4. 有一些工具可以让 powershell 拥有更好看的界面,例如 [**Oh-My-Posh**](https://ohmyposh.dev/) 和 [**Starship**](https://starship.rs/zh-CN/guide/)