我的某个水友V某分享了一个用错API的案例,opencv里的fastAtan2和cmath里的atan2单位不一样,但是返回值都是float,所以这是一个经典的基本类型丢失类型信息的案例。使用库api,遇到基本类型的返回值,一定要明白类型含义
使用-fuse-ld=mold
低版本的gcc别想了,mold你都编译不过
time_t是32位的,2038年就溢出了,glibc修了,不过不是默认的, 使用这个宏-D_TIME_BITS=64来指定
说的挺吓人的实际上不用担心,你要担心的是自定义的时间戳,比如用了int32的,得改成int64了
不过也不用担心,还有十多年你干不干程序员还不一定呢
c++的int互相转化,太坑爹了
std::cout << (-1L < 1U); // What will this output?
猜猜是几?不同的编译选项表现还不同obtain different output using -m32 Vs -m64 compiler command line options.
uint16_t x1 = 1;
uint16_t x2 = 2;
std::cout << x1 - x2 << "\n"; // What will this output?
猜猜是几?-1,因为x1 - x2 的类型是int
uint32_t x3 = 1;
uint32_t x4 = 2;
std::cout << x3 - x4 << "\n"; // What will this output?
再猜猜是几?
4294967295
unsigned short x=0xFFFF;
unsigned short y=0xFFFF;
auto z=x*y;
猜猜是不是UB? 用-fsanitize=undefined编译下
// runtime error: signed integer overflow: 65535 * 65535 cannot be represented
// in type 'int'
// SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.cpp:7:13 in
遇到整型计算问题一定要考虑坑爹的转换问题
作为一个图形学程序员,这里给你提供了一份查bug清单,我不懂图形学这里的事儿,就不班门弄斧了,建议点开看下
浮点数精度是不是存在问题? pipeline渲染管线是不是不对?
先看一段python
from contextlib import contextmanager
@contextmanager
def printing(msg: str):
print(f'Entering: {str}')
# Yield a value, making this into a coroutine function
yield 1729
print(f'Exiting: {str}')
with printing('coro context example') as val:
print(f'Got value: {val}')
c++有了协程,也可以了,作者手把手教你实现一个co_resource,代码在这里
cppcon 2021最近没啥时间看,我先鸽,后面慢慢更新
介绍if consteval的。没啥说的,consteval能简单计算了。math基本上都是consteval