Блог пользователя vmp

Автор vmp, 12 лет назад, По-английски

I've used two compilers: G++ on prompt and Dev-c and in both of them i get the right answer while the it keeps saying I'm wrong. I submitted as GNU C++ it said wrong on test 5, then i submit the same code as MS C++ it says wrong in test 9 but in both tests i tested here and got the right answer... any tips?

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
12 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

1) First of all, you should fix these compiler warnings:

x.cpp: In function 'int main()':
x.cpp:93:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
x.cpp:66:10: warning: shadowed declaration is here [-Wshadow]
x.cpp:115:12: warning: declaration of 'i' shadows a previous local [-Wshadow]
x.cpp:66:10: warning: shadowed declaration is here [-Wshadow]
x.cpp:61:22: warning: unused variable 'aux' [-Wunused-variable]
x.cpp:129:39: warning: 'points' may be used uninitialized in this function [-Wmaybe-uninitialized]

2) With GCC and -fstack-protector-all, I get an error on test 5:

*** stack smashing detected ***: ./x terminated
======= Backtrace: =========
/usr/lib32/libc.so.6(__fortify_fail+0x45)[0xf74e8245]
/usr/lib32/libc.so.6(+0x1011fa)[0xf74e81fa]
./x[0x8049fac]
/usr/lib32/libc.so.6(__libc_start_main+0xf5)[0xf7400605]
./x[0x804a2e1]

This means that your program corrupts the stack somewhere and that you should revise your memory operations. I suggest to use string instead of char[] everywhere.

P.S. Please don't use Dev-C++, it is not maintained and ships with a very old C++ compiler. You can try Visual C++ Express or MinGW with Code::Blocks instead.

  • »
    »
    12 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Oh, thank you. I don't use Dev-C, except when i have problems in gcc. I'll download Code::blocks and see what i get. :)