当前位置:网站首页>AUTOSAR从入门到精通番外篇(八)-C语言常用技巧50个
AUTOSAR从入门到精通番外篇(八)-C语言常用技巧50个
2022-08-11 08:00:00 【格图洛书】
01. 宏定义用do{}while(0)
如果定义的宏函数后面有多条语句,使用这样的方式会有问题:
#define FUNC() func1(); func2() if(bRunF) FUNC();
展开宏定义后会变成:
if(bRunF) func1(); func2();
逻辑就不对了。可以用这一的方式解决,非常好用:
#define FUNC() do{func1(); func2();}while(0)02. 数组的初始化
假如给arr的第2~6元素初始化为5,也许你会
int arr[10] = {0, 5, 5, 5, 5, 5, 0, 0, 0, 0};现在告诉你C99可以这样:
int arr[10] = {[1... 5] = 5};03. 数组的访问
你想取数组的第6个元素(下标为5),教科书教你这样做:
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n1 = arr[5];
int n2 = *(arr+5);其实你可以:
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 5[arr];也不会有错,实际上arr[5]对应*(arr+5),而5[arr]对应*(5+arr),没多大区别。
04. 结构体的初始化
结构体的初始化,传统的
边栏推荐
- 软件测试常用工具的用途及优缺点比较(详细)
- Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
- The easiest trick to support quick renaming of various files
- 1003 I want to pass (20 points)
- 1036 Programming with Obama (15 points)
- Distributed Lock-Redission - Cache Consistency Solution
- 1046 punches (15 points)
- 3.2 - classification - Logistic regression
- klayout--导出版图为gds文件
- 【415. 字符串相加】
猜你喜欢

测试用例很难?有手就行
1.2-误差来源

Serverless + domain name can also build a personal blog? Really, and soon

项目1-PM2.5预测

记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.

1061 判断题 (15 分)

无服务器+域名也能搭建个人博客?真的,而且很快

1106 2019数列 (15 分)

关于架构的认知

The most complete documentation on Excel's implementation of grouped summation
随机推荐
Creo9.0 特征的成组
Square, multi-power, square root calculation in Tf
高德能力API
excel 透视表 值显示内容 不显示计数
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
1096 big beautiful numbers (15 points)
【C语言】每日一题,求水仙花数,求变种水仙花数
1071 小赌怡情 (15 分)
动态代理学习
欧拉函数(用欧拉筛法求欧拉函数)
FPGA 20个例程篇:11.USB2.0接收并回复CRC16位校验
Test cases are hard?Just have a hand
少年成就黑客,需要这些技能
1046 punches (15 points)
1002 Write the number (20 points)
囍楽cloud task source code
JUC并发编程
1051 Multiplication of Complex Numbers (15 points)
Evolution and New Choice of Streaming Structured Data Computing Language
CSDN21天学习挑战赛——封装(06)