473,413 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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

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;
};


Nov 14 '05 #1
2 1530
LeTubs wrote:
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>
Nov 14 '05 #2

"Jon Willeke" <j.***********@verizon.dot.net> wrote in message
news:74******************@nwrdny02.gnilink.net...
LeTubs wrote:
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>


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


Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave A | last post by:
The following C code specifies the interface into a DLL. I need to access it from C#. How do I do declare it? I have done simple ones before but this particular API requires a pointer to a struct...
9
by: Project2501a | last post by:
hey guys, Question about the internal workings of Access. How are controls added in the Form.Controls collection? I mean, in which order? the order place them on the form? is there a way to...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
9
by: vijay | last post by:
Hello, I am new to C Programming and just started reading K&R. I was about to finish the pointers chapter but got very confused with: 1. int arr; >From what I have read, arr is a pointer to...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
3
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef...
9
by: Rick | last post by:
Hi guys!! just one question, can i send pointers from VC++ 2005 to a vc++ 6.0 dll? if it is possible, how can i do this? does VS2005 have rules to send pointers? Regards.
5
by: Joel | last post by:
(1) Can anyone please tell me the exact meaning of primitive types in the MSIL context. (2) Also what is the meaning of the world inline? (3) What is the meaning of the statement: "You should...
5
by: _dee | last post by:
I'm working on a port of a legacy app originally written in C. Data was compacted into bit fields. Are there any sites or books that cover optimized handling of this type of data? I'd need to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.