Compiler quirks:Some bugs and features looks weird but really exists
Разница между en3 и en4, 18 символ(ов) изменены
There are some bugs and features exists while compiling a c++ code,it looks weird but really exists on standard c++ compiler.I'll write down the bugs and features here to remind you to aware of them.↵
# 1.stl::vector:fail to use operator "=".↵
I was trying to implent the merge function of segment tree while solving [the task](https://codeforces.net/contest/1037/problem/H),and the initial code is ↵

<spoiler summary="here">↵

```↵
int mrg(int x,int y,int l,int r){↵
if(x == -1 || y == -1)↵
return x + y + 1;↵
int u = sum.size();↵
sum.push_back(sum[x] + sum[y]);↵
lc.push_back(-1);↵
rc.push_back(-1);↵
if(l == r)↵
return u;↵
int m = (l + r) >> 1;↵
lc[u] = mrg(lc[x],lc[y],l,m);↵
rc[u] = mrg(rc[x],rc[y],m + 1,r);↵
return u;↵
}↵
```↵

...↵
</spoiler>↵

 and found that it will get WA on test #6 using the language `C++14(GCC 6-32)`.Then I found out that the ↵

<spoiler summary="code">↵

```↵
lc[u] = mrg(lc[x],lc[y],l,m);↵
rc[u] = mrg(rc[x],rc[y],m + 1,r);↵
```↵

...↵
</spoiler>↵

 might got wrong.That because the location of `lc[u]` changed after using `lc.push_back()` and the same as `rc[u]`,so the operator "=" might not work.↵

The bug have been fixed since `C++17(GCC 7-32)`,but if you compile your code using language `C++` and the previous version before
 `C++17(GCC 7-32)`,the bug still exists.↵

# 2.vector:Can vector be compiled by head file <algorithm>?↵

I've participated on a school contest and found that a code with `stl :: vector` ran successfully without head file `<vector>`,after that,I made some testing and found something miraculous:↵

If the compiler is on Windows system (on codeforces,Dev c++ on Windows,etc),you can use `<algorithm>` instead of `<vector>` to compile `stl :: vector`,but if the compiler is on Linux system (Luogu,and so on),`<algorithm>` is unable to compile `stl :: vector`,especially for Chinese who is willing to engage on Olympics in informatics,please be aware of this.↵

For more such bugs and features,you can reply to the comment and I'll put some of them that sometimes exists but not well-known here.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский zhengqingyuan 2024-09-19 08:34:25 69
en5 Английский zhengqingyuan 2024-09-19 08:33:19 89
en4 Английский zhengqingyuan 2024-09-18 10:05:50 18 Tiny change: 'ion before,the bug s' -> 'ion before `C++17(GCC 7-32)`,the bug s'
en3 Английский zhengqingyuan 2024-09-18 10:01:50 217
en2 Английский zhengqingyuan 2024-09-18 09:53:30 1644 (published)
en1 Английский zhengqingyuan 2024-09-16 17:13:55 285 Initial revision (saved to drafts)