UPD: Thanks to jalsol and purplesyringa for solution to this problem. And yes, it was my problem, not GCC's one) Moreover, it was because #pragma GCC optimize("Ofast")
and it's not a big question why it doesn't work in Clang :)
Problem:
As you may know, usually on competitions (especially when you're coding on linux OS) GCC compiler is being used. And GCC is utterly the most popular one, I can't argue on this point. What about Clang — it's commonly known as MacOS compiler because Apple with zealous gruffness built it in the all of their PC products.
So a few weeks ago I switched OS from Ubuntu to Deepin because according to some circumstances I thought that my OS had been crashing) and btw I was right and btw Deepin is much user friendly than Ubuntu. So I changed OS then installed Clion and closed my PC, and for a week or so I used only my mac laptop, because it was just improbable to debug in such a fword compiler. Like ok, you open an application (CodeBlocks or Clion) begin debugging and by example you want to look at the variable that as you thought has some useful information that may help you rectify the thing. But instead of your variable you get "< optimized_out >" and you're obliged to make this variable global and it makes you waste some time). Ok this is not the whole problem, when you're trying :) to debug some passage of the code instead of looking through all lines of it (step by step) as Clang compiler does, you're striding, making giant leaps on other uproar compiler is kinda goading you, and in this hustle is easy to forget what you have been doing)))
Clang does NOT have this all stuff, maybe it's not the best in compiling :) or running program, but it's marvelous in debugging. So if you're interested in using a debugger, move to Clang. Good luck on contest. Bye!
Evidences:
First
GCC
Clang
Second
GCC
Clang
It's kinda hard to visualize the situation you're speaking of. It'd be much better if you could provide some examples. I mean some examples(screenshots?) where clang and gcc would behave differently and Clang would be more friendly.
Reasonable comment. I added evidences (screenshots)
Judging from screenshots, the ones with GCC are made in CLion, and the ones with Clang are made in Code::Blocks. Is it really the difference in compilers or it's the difference in compiler options both IDEs provide to compiler?
Clang can also optimize variables out, because it's a way to generate better and faster code.
Difference in compilers, the debug process will go the same way if I swap these two IDEs.
Auto comment: topic has been updated by arseniyx92 (previous revision, new revision, compare).
No, that's not what you're expected to do at all. 'Optimized out' means literally that -- optimized out. If GCC optimizes out a variable and Clang doesn't, it means that Clang has a worse optimizer than GCC, at least in this case. The right solution is to disable most optimizations (e.g. using
-O1
or even-O0
) when debugging code.Why do you need flags or something while doing such an elementary thing (I mean not as complex as in production program would be) as competitive programming? And what about 1 example: this leaps and "unpredicted" behaviour of debugger and such a strange value of 'm' variable while in reality it was '1'?
I honestly don't think you got it (or maybe I misunderstood, idk).
The compiler should hardly optimize anything by default. However, looking through your codes, I notice that you have
-Ofast
enabled. You already have the flags enabled, not via the actual command, but via#pragma
.Try removing that (and make sure your GCC configurations only has
-O1
or-O0
as mentioned above), then check if the problem still persists.Jesus, you're right), it was due-to "-Ofast" enabled) ahahah))))
Hooray! It solved the whole thing. Thanx)
I locally use Clang, but when submitting to Codeforces, I use GCC.
Well, another possible approach was to just debug and fix the problem in that particular Ubuntu package that was bothering you. If you are not competent enough as a software developer to do this yourself, then have you at least submitted a bugreport?
Auto comment: topic has been updated by arseniyx92 (previous revision, new revision, compare).