Some bugs and features looks weird but really exists

Revision en7, by OtterZ, 2025-03-28 09:15:49

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,and the initial code is

here

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

code

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 ?

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.Also, in Windows <iostream> is able to compile stl :: vector and it's invalid to use <iostream> to compile stl :: vector in Linux.So,for participants,especially for Chinese who is willing to engage on Olympics in informatics,please be aware of this.

3.Have to trun __int128 to long long or int by hand

When I was writting codes,I found that:

__int128 I = 1;
fx[i] = I * (I * s1 * mod * fx2[i] + I * s2 * mod2 * fx[i]) % (mod * mod2) % 1000000007;

The code goes wrong due to __int128 goes wrong when turning to int or long long while printing or setting int or long long varibles.It should be:

__int128 I = 1;
fx[i] = (long long)(I * (I * s1 * mod * fx2[i] + I * s2 * mod2 * fx[i]) % (mod * mod2)) % 1000000007;

instead.

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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English OtterZ 2025-03-28 09:15:49 542
en6 English OtterZ 2024-09-19 08:34:25 69
en5 English OtterZ 2024-09-19 08:33:19 89
en4 English OtterZ 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 English OtterZ 2024-09-18 10:01:50 217
en2 English OtterZ 2024-09-18 09:53:30 1644 (published)
en1 English OtterZ 2024-09-16 17:13:55 285 Initial revision (saved to drafts)