跳转至

忽视编译器的警告

注意力不要被前面的 -Wsign-compare 吸引了,后面的警告中提示了重要的未初始化错误。

应当检查所有警告。

simonhe@ubuntu:~/htc/250618$ g++ T1.cpp -O2 -Wall
T1.cpp: In function ‘void work_pre()’:
T1.cpp:87:22: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   87 |     for(int i = 1; i < ps.size(); i++) {
      |                    ~~^~~~~~~~~~~
T1.cpp: In function ‘void work_suf()’:
T1.cpp:125:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  125 |         for(int i = 1; i < ps.size(); i++) {
      |                        ~~^~~~~~~~~~~
T1.cpp: In function ‘int main()’:
T1.cpp:166:26: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  166 |         for(int j = 0; j < s[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~
T1.cpp: In function ‘void work_pre()’:
T1.cpp:95:16: warning: ‘mx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |         } else if(lcp == mx && pre == i - 1) {
      |                ^~
T1.cpp:86:13: warning: ‘mxp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |     int mx, mxp, cnt = 0, pre = -1;
      |             ^~~
T1.cpp: In function ‘void work_suf()’:
T1.cpp:146:22: warning: ‘mx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  146 |     for(int i = 0; i < mx; i++) {
      |                    ~~^~~~
\[ 100pts\to 10pts\\ 400pts\to 310pts \]

珍爱生命,认真看警告