473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some help with pointers......a nd 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,&som efunction,(void *)&conninfo )
}

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


Nov 14 '05 #1
2 1551
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,&som efunction,(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******** **********@nwrd ny02.gnilink.ne t...
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,&som efunction,(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....anyh ow 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
368
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 that contains an array of other structs. typedef struct { int nWidth; int nHeight; DWORD dwFlags; } HCA_MODE; typedef struct
9
1630
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 re-arrange them as i please? My solution is to remove the objects from the Form.Controls collection, place them in a tmpCollection, arrange tmpCollection as I please, and then re-add them back into the Form.Controls collection. thanks
7
2216
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 http://www.eskimo.com/~scs/C-faq/faq.html but it doesn't seem to answer my questions... So, I've made an example behind, with some included questions...
9
2248
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 the first int and &arr is a pointer to the whole array of 10 ints. Then why does sizeof(arr) gives 40 while sizeof(&arr) gives 4. Shouldn't is be the other way around.
16
2308
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 subject pointer does not refer to an object suitably aligned in storage. It is guaranteed that a pointer to an object may be converted to a pointer to an object whose type requires less or equally strict storage alignment and back again without change;...
3
1777
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 System::Byte ByteArray __gc;
9
1436
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
1434
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 bear in mind, however, that decimal is not implemented under the hood as a primitive type, so using decimal will have a performance impact on your calculations." ?
5
1877
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 develop optimized functions for reading and writing, and given the volume of source, I don't want to end up with pages of obscure code. (Surprisingly, the original C was pretty clear).
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.