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

Автор arseniyx92, история, 5 лет назад, По-английски

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

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

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

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.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by arseniyx92 (previous revision, new revision, compare).

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

И тут в блог на танке врывается Visual Studio!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +47 Проголосовать: не нравится

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

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.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -26 Проголосовать: не нравится

    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'?

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

      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.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I locally use Clang, but when submitting to Codeforces, I use GCC.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

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

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?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by arseniyx92 (previous revision, new revision, compare).