gcc on windows generating garbage? windows vs linux

前端 未结 2 602
自闭症患者
自闭症患者 2021-01-23 09:31

I\'m trying to find out why in windows has so much more instructions for the same program than linux. So I just used int a=0xbeef; and printf(\"test\\n\");

相关标签:
2条回答
  • 2021-01-23 10:07

    You seem to be compiling with old 3.x series gcc, you'd better upgrade. Newer versions don't invoke alloca. I suspect the particular version of alloca might use register convention so the mov 0x10,%eax is probably setting up the argument for that call.

    __main is a startup function defined in crtbegin.o that executes global constructors and registers a function using atexit that will run the global destructors.

    Also note that main gets special treatment, like the stack alignment code and the above-mentioned initialization. It may be a good idea to instead compare a "plain" function if you are just interested in code generation issues.

    0 讨论(0)
  • 2021-01-23 10:15

    One notes that in the upper example the compiler is calling puts, while in the lower it is printf. I would suspect you have optimization on in the top example, but not on the lower example.

    It also might be a debug vs non-debug build.

    0 讨论(0)
提交回复
热议问题