Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: venom4u31 on March 05, 2012, 07:52:57 pm

Title: Aparent error in Code Blocks
Post by: venom4u31 on March 05, 2012, 07:52:57 pm
I was writing a program in code blocks and I have stumbled upon this error... I ran the program execution just after the initialization of s1 and s2 and although s2 is called just like s1 in the watch window, it has a totally different value than it should have.
s1 and s2 are not global or declared in any other function of this project. In this example j=0, d=1;


Can you please tell me any possible reason for which s1 and v->v+j+d have different values but identical addresses? I can't think of any. There you have a descriptive image (I can assure you it's not edited):

(http://s13.postimage.org/ftyyetwr9/code_blocks_error.png)
Title: Re: Aparent error in Code Blocks
Post by: stahta01 on March 05, 2012, 08:11:34 pm
Use the command line debugger.
Verify the problem either exists or does not exist using the command line debugger.

POST Information regarding your setup.
CB Version
OS Name and version
Compiler version
Debugger version

Tim S.
Title: Re: Aparent error in Code Blocks
Post by: venom4u31 on March 05, 2012, 08:25:21 pm
The Code Blocks Version is 10.05
The OS is Windows 7 32 bits
The compiler is GNU GCC but I don't know how to find its version.
The debugger name and version is GNU gdb 6.8

I don't know how to verify if a problem exists using the command line debugger, I know about the existence of the problem when I am seeing that two pointers point to the same address and their value greatly differs.

Also, I noticed that there are two commas after *((int*)v->v+j+d) = 23,, and v->v+j+d = (void *) 0x22fea9,,. Could that mean anything?
Title: Re: Aparent error in Code Blocks
Post by: stahta01 on March 06, 2012, 12:07:34 am
Can someone else help this poster; I really do not used debug enough to help them.

The thinks stated in debug threads are:

Turn on debug logging (I have no idea how to do.)
Use the debug nightly build. http://forums.codeblocks.org/index.php/board,20.0.html (http://forums.codeblocks.org/index.php/board,20.0.html)
Verify the problem exists on the command line as stated in past.
Upgrade/downgrade the gdb version (no idea which version work best.)

Tim S.
Title: Re: Aparent error in Code Blocks
Post by: ollydbg on March 06, 2012, 01:04:07 am
@OP
Please post your code snippet so that I can test it.

In fact, I'm not fully understand what's OP's problem, what is the watch expression, and what's the exact value it should be? Please list them.
Title: Re: Aparent error in Code Blocks
Post by: venom4u31 on March 06, 2012, 08:45:35 am
@OP
Please post your code snippet so that I can test it.

In fact, I'm not fully understand what's OP's problem, what is the watch expression, and what's the exact value it should be? Please list them.


To have the code working there are several files that need to be working. If you want I can paste the basic structure of v to make you understand what it is about.
Code
//v is a TMult element that represents a structure that can hold any type of element


typedef int(*TFComp)(const void *, const void *);
typedef struct
{ size_t d;        /* element size */
  TFComp fid;      /* function that checks the equality of two elements */
  TFComp ord;      /* ordering function */
  void *v, *s, *t; /* value vector adresses: v for beginning, s for end of used memory and t for available memory */
} TMult;



Regarding values, I think it's pretty clear. The vector v->v is listed (it's void with int values in it), the initialization of s1 is clear: it's v->v+j (j=0 and d=1, j, d are int numbers). And s2=v->v+j+d which is supposed to be s1+1. Now, s1 is correctly v->v, as it says there, its value is 1. However s2, although it holds the exact same memory address as v->v+j+d, instead of having the value 23 in it, it has a huge number stored.
Title: Re: Aparent error in Code Blocks
Post by: ollydbg on March 06, 2012, 08:54:06 am
Ok, you can do:

1, download the debugger branch nightly build version
2, enable the full debug log output
3, past all the debugger's debug log text when you watch those variables.

Mean while, I will test your sample code too.
Title: Re: Aparent error in Code Blocks
Post by: ollydbg on March 06, 2012, 09:03:02 am
So, what's your problem? Here is my test code and see the screen shot below:

code:
Code
#include <stdio.h>

//v is a TMult element that represents a structure that can hold any type of element

typedef int(*TFComp)(const void *, const void *);


typedef struct
{ size_t d;        /* element size */
  TFComp fid;      /* function that checks the equality of two elements */
  TFComp ord;      /* ordering function */
  void *v, *s, *t; /* value vector adresses: v for beginning, s for end of used memory and t for available memory */
} TMult;


TMult a;

int main()
{
    TMult *p = &a;
    p->v = (void*)0x1;
    p->s = (void*)0x2;
    return 0;
}


screen shot:
(http://i683.photobucket.com/albums/vv194/ollydbg_cb/2012-03-06160142.png)


I can't see any thing wrong.

EDIT: would you mind to extend my example to show us the errors?
Title: Re: Aparent error in Code Blocks
Post by: Jenna on March 06, 2012, 09:36:09 am
Please create a simple working example, that shows the issue, not just a stub.

From what I see, the issue most likely occurs because of incorrect referencing/dereferncing of pointers, probably caused by a lack of basic programming knowledge.

Be aware, that this forum/website, does not teach programming and is not meant to find programming errors (if they are not inside C::B's own code).
Such questions violate our forum rules, and every user has accepted these rules with registering here.

So your topic might get locked !
Title: Re: Aparent error in Code Blocks
Post by: venom4u31 on March 06, 2012, 09:41:52 am
Please create a simple working example, that shows the issue, not just a stub.

From what I see, the issue most likely occurs because of incorrect referencing/dereferncing of pointers, probably caused by a lack of basic programming knowledge.

Be aware, that this forum/website, does not teach programming and is not meant to find programming errors (if they are not inside C::B's own code).
Such questions violate our forum rules, and every user has accepted these rules with registering here.

So your topic might get locked !


I'm sorry, I didn't want or expect to have the code solved or a valid solution provided. I just wanted to know a possible reason for which such a thing might happen. Since I didn't find any logical reason for two pointers initialized the same way to have completely different values, I thought that might have happened because a code::blocks error.