debug vs release version

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey22
    New Member
    • Feb 2007
    • 105

    debug vs release version

    Hi all,

    I have some theoritical questions.

    1. Why sometimes any piece of code works fine in th debug version and fails in the release version ?

    could anyone please state the difference between relase and debug version?

    2. int *ptr[10]; //10 pointers pointing to an integer

    what happens if we do ptr++ ?What should I do if I want to acess all the pointers?

    int(*ptr)[10]; //pointer pointing to an array of integers
    what happenes if we do ptr++ here ?Can I do it?

    Need little bit explanation about it.

    Thanks
  • jorba101
    New Member
    • Jun 2008
    • 86

    #2
    1. No clue. I guess you're talking about Visual C++. No clue anyway

    2. It will increment the pointer the memory positions that take an int. In the particular case of a 32-bit int, it will increase the memory position in 4.

    3. It will increment the pointer the memory positions that take 10 ints. In the case of 32-bit int's, it will increase it 40 positions.

    Why? because the "++" operator on pointers increments the address the number of bytes of the pointed type.

    Comment

    • pootle
      New Member
      • Apr 2008
      • 68

      #3
      In answer to 1, the most common reason is because the timing changes between the two. The debug build includes loads of checks that slows it down a lot.

      Regards

      Comment

      • mickey22
        New Member
        • Feb 2007
        • 105

        #4
        Thank you for the reply.

        ptr++ in the second case increases by 40 ----- does it mean that ptr++ means it points to the last element of the array it is pointing to?
        If I want to acess some middle element how do I call through this pointer.

        For eg: a[]={1,2 ,3,4};
        int (*ptr)[4];

        if I want to print out a[2]=3 using *ptr how can i do it?

        Comment

        • jorba101
          New Member
          • Jun 2008
          • 86

          #5
          Originally posted by mickey22
          ptr++ in the second case increases by 40 ----- does it mean that ptr++ means it points to the last element of the array it is pointing to?
          Not the last, but the next.

          e.g.:

          ptr points to the first position

          ptr++ -> will get it to point to the next one

          Originally posted by mickey22
          If I want to acess some middle element how do I call through this pointer.

          For eg: a[]={1,2 ,3,4};
          int (*ptr)[4];

          if I want to print out a[2]=3 using *ptr how can i do it?
          first you have to get one of the four pointers in (*ptr)[4] to point to a[], you can do it like:

          Code:
          ptr[0] = a;
          (in this case you take ptr[0]).

          Afterwards, you can access a[2] by accessing either a[2] or ptr[0][2].

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by mickey22
            1. Why sometimes any piece of code works fine in th debug version and fails in the release version ?

            could anyone please state the difference between relase and debug version?
            Debug code contains all the information that the symbolic debugger requires to locate the symbols in memory. Also it is normal to switch off the optimiser when producing a debug build otherwise it can be very hard to follow the code through the debugger. The debug build is often many times bigger than the release build.

            As has been mentioned time issues can occur in debug builds because of the increase code size but there can be other effects too. An old version of the Microsoft compiler used to initialise automatic variables to 0 in the debug build. This meant that if you forgot to initialise a variable you could create a working debug build and a non-working release build.

            Originally posted by mickey22
            2. int *ptr[10]; //10 pointers pointing to an integer

            what happens if we do ptr++ ?What should I do if I want to acess all the pointers?

            int(*ptr)[10]; //pointer pointing to an array of integers
            what happenes if we do ptr++ here ?Can I do it?
            In your first case [code=c]int *ptr[10];
            ptr++;[/code]the code is not compilable because ptr is not an l-value because in fact ptr is not a pointer, it is an array. Because of this the ++ operator is not valid for it.

            In the second case [code=c]int (*ptr)[10];
            ptr++;[/code] as stated already ptr++ increments the address pointed to by sizeof(*ptr). I would recomend you google for pointer arithmetic, there are many pages explaining it.

            Comment

            Working...