败犬日报 2025-09-09
败犬日报 2025-09-09
1. java, python 默认引用语义
变量存储的是对象的引用,赋值只会复制引用。
对应的是值语义(典型的就是 C++)。
2. Concept-Model Idiom 非侵入式多态
https://gracicot.github.io/conceptmodel/2017/09/13/concept-model-part1.html
如果自己实现还是要写一堆,直接用 proxy 库就可以自动生成了。
3. 一个 GCC 9.X bug
GCC 9.X 编译参数 -O2,输入 1,会输出 1 0。
cpp
#include <iostream>
long long n;
bool ac[1];
int main() {
std::cin >> n;
for (int i = 1; i <= n; i++) {
ac[i] = (((n - i + 1) % 2) == 0);
}
std::cout << ac[n] << " " << (((n - n + 1) % 2) == 0) << "\n";
return 0;
}gcc bugzilla 里没找到。
群友 bisect 了一下,是 https://github.com/gcc-mirror/gcc/commit/2e103ae2138ede8a4db831dea30065fe0041bc58 引入的问题,https://github.com/gcc-mirror/gcc/commit/523fe5b61119c17d9b5adf4a6a4cffa10cfaacf7 开始问题消失。
感兴趣的可以继续研究。