Some help with pointers......and passing them around.

L

LeTubs

Hi
I'm think I'm having some problem with pointers.....
namely passing them around...Or I think ? I've used
gdb to find the following (note conn is of type MYSQL *conn).

Program received signal SIGSEGV, Segmentation fault.
0x804a53e in get_next_chunk (conn=Error accessing memory address 0xbf000a38:
Bad address.
) at fmysql.c:315

Is what I'm doing correct below. Also is there any programs or tips to
debug pointers (ie checking values, tracing). Any tips or pointers (no pun
intended) would be greatly appreciated.

Here's what I doing ...

functionA( MYSQL *conn){

struct connect conninfo;

/* Is this correct */
conninfo.conn = conn;

/* then the conninfo is then passed to a thread */
pthread_create(.....,NULL,&somefunction,(void *)&conninfo )
}

struct connect{
MYSQL *conn;
int var1;
int var2;
};
 
J

Jon Willeke

LeTubs said:
I'm think I'm having some problem with pointers.....
namely passing them around...Or I think ? I've used
gdb to find the following (note conn is of type MYSQL *conn).

Program received signal SIGSEGV, Segmentation fault.
0x804a53e in get_next_chunk (conn=Error accessing memory address 0xbf000a38:
Bad address.
) at fmysql.c:315

Is what I'm doing correct below. Also is there any programs or tips to
debug pointers (ie checking values, tracing). Any tips or pointers (no pun
intended) would be greatly appreciated.

Here's what I doing ...

functionA( MYSQL *conn){

struct connect conninfo;

/* Is this correct */
conninfo.conn = conn;

/* then the conninfo is then passed to a thread */
pthread_create(.....,NULL,&somefunction,(void *)&conninfo )
}

struct connect{
MYSQL *conn;
int var1;
int var2;
};

You are passing the address of conninfo, a local variable, to a function
that will cause it to be dereferenced after the end of the containing
function. A similar question is answered in the FAQ:

<http://www.eskimo.com/~scs/C-faq/q7.5.html>
 
L

LeTubs

Jon Willeke said:
You are passing the address of conninfo, a local variable, to a function
that will cause it to be dereferenced after the end of the containing
function. A similar question is answered in the FAQ:

<http://www.eskimo.com/~scs/C-faq/q7.5.html>

Thanks it for making it clear what I'm doing wrong however, due to this I've
actaully spotted
a design error (after looking at the above question, I should make conn a
global variable
( as it won't change after it has been intialised, and don't pass it around,
though not to sure
if this will allowed with threads....anyhow I'll cross that bridge when I
come to it....
But many thanks for pointing what I was doing and the info for C-faq as it
will come in handy
Thanks again

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top