vmp's blog

By vmp, 12 years ago, In English

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?

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
12 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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. :)