C/C++
学习小记
洲游
新时代农民工,愿世界和平!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
利用gcc -E -P 进行宏替换 宏展开 预处理文件
背景:有的时候,非源码中的文件,需要使用到源码头文件中的一些宏,如连接脚本(link.ld)中,会用到源码中定义分配的内存地址宏,此时就可以用 gcc -E -P 命令对link.ld中的宏进行替换,否则无法识别宏。待展开文件:link.ld#include “memory.h"SECTIONS{ . = MEM_TEXT_BASE; .text : { *(.text) } . = MEM_DATA_BASE;...原创 2022-05-18 12:46:45 · 1600 阅读 · 0 评论 -
C语言 日志打印限频
参考内核打印限频功能#include <stdio.h>#include <time.h>#define FALSE 0#define TRUE 1/* * 日志限频:打印第一条,之后间隔intervalMs打印一条 */#define PRINT_LIMIT(intervalMs) \ static long int lastTime = 0; \ long int currTime = clock(); \ int printFla原创 2022-05-10 19:29:46 · 913 阅读 · 0 评论 -
C语言 可变参数 函数间传递
#include <stdio.h>#include <stdarg.h>typedef unsigned int u32;// void printf(const char *fmt, ...)void MyPrintf(u32 level, const char *pFunName, u32 line, const char *fmt, ...){ char buf[256]; va_list ap; if (level < 1) {.原创 2022-03-11 17:31:04 · 3012 阅读 · 0 评论 -
C语言 联合体中嵌套结构体,可以省略结构体变量名
1 常规编码方式#include <stdio.h>typedef union { struct { int a : 4; int b : 4; int c : 4; int d : 4; int rsv : 16; } valBits; int val;} U_TEST_UNION;int main(){ U_TEST_UNION uTest = {0}; uTest.val = 0x12345678; printf("val: 0x%x\n"原创 2022-02-25 22:00:10 · 2335 阅读 · 1 评论 -
C语言三个点“...“符号含义之数组批量赋相同值
#include <stdio.h>int main(){ int array[10] = { [2 ... 5] = 0xA5A5A5A5, [7 ... 9] = 0x5555AAAA, }; for (int i = 0; i < 10; i++) { printf("a[%d] = 0x%x\n", i, array[i]); } return 0;}...原创 2022-01-24 14:44:22 · 788 阅读 · 0 评论
分享