c++ 学习笔记
时间:2020-02-20 13:26:15
收藏:0
阅读:55
1. 变量定义的时候,多使用 auto 关键字。
auto x = (uint8_t)y.x
2. 很多宏定义都可以使用 constexpr 来代替,有很多好处。唯一需要宏定义的地方是预处理。
参考:https://stackoverflow.com/questions/42388077/constexpr-vs-macros
3. #include <stdint.h> 可以用 #include 来代替。
4. format string is not a string literal(potentially insecure) 这个警告是在不定参数的函数调用中会出现,起因是编译器没有那么智能。
所以对于类似于 char str[] = "xyz"; log(str) 这样的调用就会报错,有两种解决方法:
- 显式的写出来 log("xyz")
- 增加第二个参数 log(str, nullptr)。
5. strcat 用于把一个字符串追加到另外一个字符数组里面。
原文:https://www.cnblogs.com/ramlife/p/12320417.html
评论(0)