标签:ble highlight color alc rgba 暂停 div 大内存 预编译
xxx.c文件经历的一系列编译过程:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
/*
* gcc
*
* GCC的分布编译
* xxx.c文件 -> xxx.exe可执行文件
* 1、预处理 ------------------------------------------------------
* - hello.c文件 生成hello.i文件,需要指令 -E
* - hello.i 也是一个c程序
* - 预处理阶段展开头文件,宏替换,条件编译,取消注释
*
* 命令
* gcc 文件名 -E
* gcc 文件名.c -E -o 文件名.i
*
* 导入的头文件在预编译中展开,文件大小变化
*
* 2、编译 ------------------------------------------------------
* - xxx.i 文件 编译生成 xxx.s 文件 指令 -S
* - xxx.s 文件是一个汇编文件,
* - 编译阶段主要是语法的检测
* - gcc 文件名.i -S -o 文件名.s
* 3、汇编 ------------------------------------------------------
* - xxx.s 汇编文件 生成 hello.o 文件需要指令 -c
* - xxx.o 是一个二进制文件
* - 汇编阶段主要是生成让机器识别的二进制文件
*
* 4、链接 ------------------------------------------------------
* - 将hello.o 生成 hello.exe 可执行文件
* - 可以在终端中执行此文件
* gcc 文件名.o -o 文件名.exe
*
* 指令参数
* -E -> -S -> -c
* xxx.c
* -> xxx.i 预处理后的源码文件
* -> xxx.s 编译后的汇编文件
* -> xxx.o 汇编编译后的二进制文件
* -> xxx.exe 可执行文件
*
* */
mspaint 画图
notepad 记事本
calc 计算器
control 控制面板
wmic memphysical get maxcapacity 查看最大内存容量
System函数可以让C语言程序执行操作系统命令
也就是将命令以字符串的形式传入执行
该函数需要包含标准库头文件 #include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
/*printf("Hello, World!\n");*/
system("gcc -v");
return 0;
}
system("pause");
可用于暂停程序,防止程序运行过快窗口结束
#include <stdio.h>
#include <stdlib.h>
void myFunction() {
printf("my custom function \n我的自定义函数 \n");
}
int main() {
myFunction();
return 0;
}
#include <stdio.h> #include <stdlib.h> void myFunction() { printf("my custom function \n我的自定义函数 \n"); } void errorC4996() { char buf[1024] = {0}; sprintf(buf, "%s", "aaa"); printf("%s", buf); system("pause"); } int main() { errorC4996(); return 0; }
老版本的函数存在内存安全隐患
解决方案1:使用加上后缀了_s的安全化的函数进行替代
#include <stdio.h> #include <stdlib.h> //#define _CRT_SECURE_NO_WARNINGS void myFunction() { printf("my custom function \n我的自定义函数 \n"); } void errorC4996() { char buf[1024] = {0}; sprintf_s(buf, "%s", "aaa"); printf_s("%s", buf); system("pause"); } int main() { errorC4996(); return 0; }
解决方案2:或者是包含一个宏
#include <stdio.h> #include <stdlib.h> #define _CRT_SECURE_NO_WARNINGS void myFunction() { printf("my custom function \n我的自定义函数 \n"); } void errorC4996() { char buf[1024] = {0}; sprintf(buf, "%s", "aaa"); printf("%s", buf); system("pause"); } int main() { errorC4996(); return 0; }
解决方式3:使用禁用警告
#include <stdio.h> #include <stdlib.h> //#define _CRT_SECURE_NO_WARNINGS #pragma warnings(disable:4996) void myFunction() { printf("my custom function \n我的自定义函数 \n"); } void errorC4996() { char buf[1024] = {0}; sprintf(buf, "%s", "aaa"); printf("%s", buf); system("pause"); } int main() { errorC4996(); return 0; }
标签:ble highlight color alc rgba 暂停 div 大内存 预编译
原文地址:https://www.cnblogs.com/mindzone/p/13930351.html