-3

I compiled c++ file with mingw32. It's compiled successfully but not working. What's the problem?

my command : x86_64-w64-mingw32-g++ -o xx test.cpp

phlmox
  • 1
  • 1
  • 3
    Probably a bug in your code. – Eljay May 09 '20 at 13:55
  • 1
    Read [*How to debug small programs*](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) and compile with `x86_64-w64-mingw32-g++ -g -Wall -Wextra -o xx test.cpp` – Basile Starynkevitch May 09 '20 at 13:56
  • 2
    You have to tell us at least the symptoms: "not working" could mean anything from giving the wrong result, to crashing your computer. How exactly did you run it? What exactly happened? What did you expect to happen instead? – Useless May 09 '20 at 14:03
  • ***It's compiled successfully but not working. What's the problem?*** Most likely you have a bug in your code. – drescherjm May 09 '20 at 15:08

1 Answers1

3

Just because a program compiles does not in any way mean that it is free of errors. It only means that it is syntactically valid.

The compiler has no way of knowing your intentions, so it obviously cannot flag any logic errors in your code.

There are also a lot of things in C++ that are valid syntax but that you are not allowed to do and invoke undefined behaviour. The compiler is not required to flag such issues, you have to know all the rules and abide by them. If any part of your code contains UB, the compiler has no obligation to generate anything sensible for any parts of your program.

That something compiles means next to nothing as far as correctness goes. It's a very low bar.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • 2
    No only the compiler is *not* required to flag all UB, but it can be proven that **the compiler cannot flag most undefined behavior** - [Rice's theorem](https://en.wikipedia.org/wiki/Rice's_theorem) – Basile Starynkevitch May 09 '20 at 14:03