前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++ 动态新闻推送 第44期

C++ 动态新闻推送 第44期

作者头像
王很水
发布2022-01-19 16:11:11
1830
发布2022-01-19 16:11:11
举报
文章被收录于专栏:C++ 动态新闻推送

C++ 动态新闻推送 第44期

文章

我的某个水友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互相转化,太坑爹了

代码语言:javascript
复制
std::cout << (-1L < 1U); // What will this output?

猜猜是几?不同的编译选项表现还不同obtain different output using -m32 Vs -m64 compiler command line options.

代码语言:javascript
复制
uint16_t x1 = 1;
uint16_t x2 = 2;
std::cout << x1 - x2 << "\n"; // What will this output?

猜猜是几?-1,因为x1 - x2 的类型是int

代码语言:javascript
复制
uint32_t x3 = 1;
uint32_t x4 = 2;
std::cout << x3 - x4 << "\n"; // What will this output?

再猜猜是几?

4294967295

代码语言:javascript
复制
unsigned short x=0xFFFF;
unsigned short y=0xFFFF;
auto z=x*y; 

猜猜是不是UB? 用-fsanitize=undefined编译下

代码语言:javascript
复制
// 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渲染管线是不是不对?

  • Is it possible that your binding the incorrect resource?
  • The wrong shader module?
  • Draw constants/uniforms correct?
  • Are sample counts what you expect?
  • Correct winding order? Topology?
  • Correct blend function?
  • Correct depth state (depth bounds, test operation, etc.)?
  • Is your shader compiler emitting code that is actually incorrect (possible with bleeding edge versions or when using newer compiler features)?
  • [co_resource: An RAII coroutine](https://vector-of-bool.github.io/2021/12/30/co_resource.html)

先看一段python

代码语言:javascript
复制
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

项目

  • asteria 一个脚本语言,可嵌入,长期找人,希望胖友们帮帮忙
  • pika也非常需要人贡献代码胖友们,redis over rocksdb
  • wasmblr 头文件级别的wasm小库,不错,Emscripten太复杂了
  • treefrog 新版本,一个mvc web框架
  • webtoolkit 新版本,一个web框架
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • C++ 动态新闻推送 第44期
    • 文章
      • 视频
        • 项目
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档