-1

I came across many questions on difference between debug and release like this one

But all are explaining same words like optimisation but nothing deeper.

I would like to know the response with a particular example for better understanding. Below is a simple dummy code for reference. Can anyone tell me the expected symbols missing and optimisations in release mode as against debug mode in reference to this example?

Even pointing to one optimisation would help

    #include<stdio.h>


    int sum(int arg1, int arg2);

    main()
    {
        int out, in1, in2;
        in1 = 1;
        in2 = 0;
        out = 0;
        while (out < 20)
        { 
            out = sum(in1 , in2);
            printf(" Current value of out [%d] = in1 [%d] + in2 [%d]\n", out, in1, in2 );
            in1++;
            in2++;
        } /*End of while*/
    } /*End of main()*/


    int sum(int arg1, int arg2)
    {
        int sum_val;
        sum_val = arg1 + arg2;
        return sum_val;
    } /*End of sum()*/
Community
  • 1
  • 1
Aadishri
  • 1,341
  • 2
  • 18
  • 26
  • You may want to [read this article](https://en.wikipedia.org/wiki/Optimizing_compiler). – Jabberwocky Oct 24 '16 at 12:00
  • 1
    Try it yourself see [this](https://godbolt.org/g/NBFrQZ) and [this](https://godbolt.org/g/sHcXUy) – P0W Oct 24 '16 at 12:01
  • So I must understand debug mode will be similar to the one with gcc option -o0 and release mode build will be one with say, gcc option -o3? Any other differences apart from optimisations? – Aadishri Oct 24 '16 at 12:16

1 Answers1

1

Debug build includes the complete symbolic debug information to aid while debugging applications where also the code optimization is not taken into account.

While in release build the symbolic debug info is not emitted and the code execution is optimized, And since the symbolic info is not put in a release build, the size of the final executable is lesser than a debug executable.

Also optimization is not the only thing that happens in release build. Refer : this


On a sample compiler using GCC-6.2, you can see the difference in the generated assembly by using -Ox flag

  • In a release build normally we want optimzation so see -O3

  • In debug build normally we want debug symbols with no optimization, with full debug info, so see -g3 -O0

Community
  • 1
  • 1
P0W
  • 46,614
  • 9
  • 72
  • 119