I have a problem with a dynamic library I am developing, but it is
really more of a pointer issue than anything else. Hopefully someone
here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another
function. For example:
int FunctionA ()
{
int result;
string myString;
myString = "12345";
result = FunctionB (&myString);
}
int FunctionB (string *myString)
{
int result;
int (*dlFunction) (string);
result = (*dlFunction) (*myString);
cout << *myString << endl;
}
Now, the following function exists within the dynamic library called
by FunctionB, above.
int dlFunction (string *passedString)
{
cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl;
}
So, now here is the problem. Everything seems to works just fine.
When dlFunction is called is will display the following output:
before: 12345
after: 12345hello
This tells me that I passed the proper pointers through these
functions, since I am able to manipulate the original "12345" string
through the dynamic library call to dlFunction. However, when the
FunctionB function continues execution, and it displays the contents
of the *myString pointer, is shows the string as containing only the
orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates
the string only within it's own context, never actually altering the
original string.
How do I pass the appropriate pointers or references to allow the
dlFunction function to alter the string being pointed to with the
*passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
Thanks,
Mike Dailey mi*********@mtdproducts.com 7 5141
On 12 Jan 2004 11:42:17 -0800, mi*********@mtdproducts.com (Mike D.) wrote: I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another function. For example:
int FunctionA () { int result; string myString; myString = "12345";
OK. First thing is to show us the definition of your "string" user-defined type.
From your usage, you've put
typedef char *string;
somewhere in your code, prior to this statement. Is that correct? result = FunctionB (&myString); }
int FunctionB (string *myString) { int result; int (*dlFunction) (string);
result = (*dlFunction) (*myString);
You left dlfunction uninitialized, so this statement isn't going to do what you
think it will do.
cout << *myString << endl;
Here, you go weird. It appears that you *don't* have a C program at all, and
thus your problem (no matter how interesting) is off topic in comp.lang.c.
While C and C++ (the language it /appears/ you are writing in) share many
constructs and philosophies, they are not identical languages. So, while (if we
ignore the C++ constructs in your code) your problem /may/ have a C solution, we
cannot assert that such a solution will apply to the C++ program you have
presented us with.
Best bet: go ask in comp.lang.c++ or one of the newsgroups dedicated to
programming on your platform.
[snip]
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group
(Opinions expressed are my own, not my employers')
"Mike D." wrote: I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this.
Sounds like it is off topic. What is a dynamic library. Ok... here goes....
I have a function that passes a pointer to a string to another function. For example:
int FunctionA () { int result; string myString;
What is a string? Probably invading implementation namespace. myString = "12345";
To do this myString must be a char*. Thus string must be a
typedef. Things are looking bad. result = FunctionB (&myString);
I don't see any definition of FunctionB, which must receive a
char**
}
int FunctionB (string *myString)
Here it is. Why wasn't it defined before use.
{ int result; int (*dlFunction) (string);
result = (*dlFunction) (*myString);
dlFunction is uninitialized. Nasal Demons are flying. cout << *myString << endl;
You never defined cout, and what are all these left shifts? Maybe
this whole thing should be made into a compilable chunk, and moved
to c.l.c++, where it might be topical.
}
Now, the following function exists within the dynamic library called by FunctionB, above.
No it doesn't. C has no dynamic libraries. I'm getting bored, so
... snip ...
--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Mike D. wrote: I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another function. For example:
int FunctionA () { int result; string myString;
myString = "12345";
result = FunctionB (&myString); }
int FunctionB (string *myString) { int result; int (*dlFunction) (string);
Ignoring the C++ portions of your code, and other OT stuff in your post,
look at the above declaration: dlFunction is a pointer to a function that
takes a *string* (whatever that is) and returns an int. However, in your
definition of dlFunction below, dlFunction is a function that takes a
*pointer to string* and returns int. Since you want the passed parameter
to be modified by the function and retain those modifications later, you
most certainly want to pass a *pointer to string*. Perhaps, what you want
here is:
int (*dlFunction) (string *);
result = (*dlFunction) (*myString);
and this should likely be:
result = (*dlFunction) (myString);
cout << *myString << endl; }
Now, the following function exists within the dynamic library called by FunctionB, above.
int dlFunction (string *passedString)
Note that this definition takes a *pointer to string* as its argument, not a
string.
-nrk.
ps: it is rather unfortunate that you gave the same name to your
pointer-to-function and function.
{ cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl; }
So, now here is the problem. Everything seems to works just fine. When dlFunction is called is will display the following output:
before: 12345 after: 12345hello
This tells me that I passed the proper pointers through these functions, since I am able to manipulate the original "12345" string through the dynamic library call to dlFunction. However, when the FunctionB function continues execution, and it displays the contents of the *myString pointer, is shows the string as containing only the orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates the string only within it's own context, never actually altering the original string.
How do I pass the appropriate pointers or references to allow the dlFunction function to alter the string being pointed to with the *passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
Thanks,
Mike Dailey mi*********@mtdproducts.com
Wow... are all newsgroups so full of condesending assholes, or did I
just get lucky?
I know fully well my code has c++ as well as C in it. It was the C
portion I asked for help with, therefore it was appropriate to ask in
this forum. The fact that I posted snippets of the C++ in my app is
irrelevent. C++ AND C can and often are used together when coding an
application.
Dlsym() is a function for accessing dynamic link libraries in C or
C++, so yes-- C DOES have the capability to access dynamic link
libraries.
The code I posted was a made-up example of what I tried to do. It is
not the actual functional code, so the fact that I didn't pick the
right function names to use for this example, or that I called the
function before declaring it is irrelevent. I posted the sample code
in the hopes that someone would simply say "here is why it isn't
working. Fix this and it should function properly."
So were all of you genious' treated like morons the first time you
asked for help with a code problem, or were you all born expert
programmers?
nrk <ra*********@deadbeef.verizon.net> wrote in message news:<U2***************@nwrddc01.gnilink.net>... Mike D. wrote:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another function. For example:
int FunctionA () { int result; string myString;
myString = "12345";
result = FunctionB (&myString); }
int FunctionB (string *myString) { int result; int (*dlFunction) (string);
Ignoring the C++ portions of your code, and other OT stuff in your post, look at the above declaration: dlFunction is a pointer to a function that takes a *string* (whatever that is) and returns an int. However, in your definition of dlFunction below, dlFunction is a function that takes a *pointer to string* and returns int. Since you want the passed parameter to be modified by the function and retain those modifications later, you most certainly want to pass a *pointer to string*. Perhaps, what you want here is: int (*dlFunction) (string *);
result = (*dlFunction) (*myString);
and this should likely be: result = (*dlFunction) (myString);
cout << *myString << endl; }
Now, the following function exists within the dynamic library called by FunctionB, above.
int dlFunction (string *passedString)
Note that this definition takes a *pointer to string* as its argument, not a string.
-nrk.
ps: it is rather unfortunate that you gave the same name to your pointer-to-function and function.
{ cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl; }
So, now here is the problem. Everything seems to works just fine. When dlFunction is called is will display the following output:
before: 12345 after: 12345hello
This tells me that I passed the proper pointers through these functions, since I am able to manipulate the original "12345" string through the dynamic library call to dlFunction. However, when the FunctionB function continues execution, and it displays the contents of the *myString pointer, is shows the string as containing only the orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates the string only within it's own context, never actually altering the original string.
How do I pass the appropriate pointers or references to allow the dlFunction function to alter the string being pointed to with the *passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
Thanks,
Mike Dailey mi*********@mtdproducts.com
Mike D. <mi*********@mtdproducts.com> scribbled the following: Wow... are all newsgroups so full of condesending assholes, or did I just get lucky?
Do you think anyone who tells you you are wrong is a condescending
asshole?
I know fully well my code has c++ as well as C in it. It was the C portion I asked for help with, therefore it was appropriate to ask in this forum. The fact that I posted snippets of the C++ in my app is irrelevent. C++ AND C can and often are used together when coding an application.
You are correct that if you need help with the C part, you should get
it here. However interoperability with C++ is defined by C++, not by
C.
Dlsym() is a function for accessing dynamic link libraries in C or C++, so yes-- C DOES have the capability to access dynamic link libraries.
No it doesn't. Dlsym() is not part of the C language, it's an
implementation-specific extension.
The code I posted was a made-up example of what I tried to do. It is not the actual functional code, so the fact that I didn't pick the right function names to use for this example, or that I called the function before declaring it is irrelevent. I posted the sample code in the hopes that someone would simply say "here is why it isn't working. Fix this and it should function properly."
If what is at fault here is Dlsym(), then we can't help you, as Dlsym()
isn't part of the C language. You want an implementation-specific
group.
So were all of you genious' treated like morons the first time you asked for help with a code problem, or were you all born expert programmers?
*I* was treated like a moron at the first time, yes. I got over it
pretty quickly.
PS. Please don't top-post, thanks.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
Mike D. writes:
[Response at end] Wow... are all newsgroups so full of condesending assholes, or did I just get lucky?
I know fully well my code has c++ as well as C in it. It was the C portion I asked for help with, therefore it was appropriate to ask in this forum. The fact that I posted snippets of the C++ in my app is irrelevent. C++ AND C can and often are used together when coding an application.
Dlsym() is a function for accessing dynamic link libraries in C or C++, so yes-- C DOES have the capability to access dynamic link libraries.
The code I posted was a made-up example of what I tried to do. It is not the actual functional code, so the fact that I didn't pick the right function names to use for this example, or that I called the function before declaring it is irrelevent. I posted the sample code in the hopes that someone would simply say "here is why it isn't working. Fix this and it should function properly."
So were all of you genious' treated like morons the first time you asked for help with a code problem, or were you all born expert programmers? nrk <ra*********@deadbeef.verizon.net> wrote in message
news:<U2***************@nwrddc01.gnilink.net>... Mike D. wrote:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this.
Ok... here goes....
I have a function that passes a pointer to a string to another function. For example:
int FunctionA () { int result; string myString;
myString = "12345";
result = FunctionB (&myString); }
int FunctionB (string *myString) { int result; int (*dlFunction) (string);
Ignoring the C++ portions of your code, and other OT stuff in your post, look at the above declaration: dlFunction is a pointer to a function
that takes a *string* (whatever that is) and returns an int. However, in
your definition of dlFunction below, dlFunction is a function that takes a *pointer to string* and returns int. Since you want the passed
parameter to be modified by the function and retain those modifications later, you most certainly want to pass a *pointer to string*. Perhaps, what you
want here is: int (*dlFunction) (string *);
result = (*dlFunction) (*myString);
and this should likely be: result = (*dlFunction) (myString);
cout << *myString << endl; }
Now, the following function exists within the dynamic library called by FunctionB, above.
int dlFunction (string *passedString)
Note that this definition takes a *pointer to string* as its argument,
not a string.
-nrk.
ps: it is rather unfortunate that you gave the same name to your pointer-to-function and function.
{ cout << "before: " << *passedString << endl;
*passedString = *passedString + "hello";
cout << "after: " << *passedString << endl; }
So, now here is the problem. Everything seems to works just fine. When dlFunction is called is will display the following output:
before: 12345 after: 12345hello
This tells me that I passed the proper pointers through these functions, since I am able to manipulate the original "12345" string through the dynamic library call to dlFunction. However, when the FunctionB function continues execution, and it displays the contents of the *myString pointer, is shows the string as containing only the orginal value of "12345."
So it appears that the dlFunction dynamic library function manipulates the string only within it's own context, never actually altering the original string.
How do I pass the appropriate pointers or references to allow the dlFunction function to alter the string being pointed to with the *passedString pointer? What am I missing/doing wrong?
Any help would be GREATLY appreciated!
I make no claims to understanding your problem. But I get the *feeling*
that you expect a function to "grow" a string. Since that function doesn't
own the space the string inhabits this seems like an unrealistic
expectation.
Although the problem is not at the boundaries, one would really like a
blackboard to describe this problem ....
To get help here you will have to rephrase your question and avoid using the
dreaded words "DLL". You do not swear in church and ....
Mike D. <mi*********@mtdproducts.com> spoke thus: Wow... are all newsgroups so full of condesending assholes, or did I just get lucky?
etc.
You just got lucky. Do yourself a favor and take a look at http://www.msu.edu/~pfaffben/writing...off-topic.html http://www.eskimo.com/~scs/C-faq/top.html
and much will be made known to you.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jr |
last post by:
Sorry for this very dumb question, but I've clearly got a long way to go!
Can someone please help me pass an array into a function. Here's a starting
point.
void TheMainFunc()
{
// Body of...
|
by: mpatnam |
last post by:
I have an executable which links to a static library (.a).
I want to provide a hook by overriding a function part of this static
library.
Eg: I have a function "int blkstart(int i)" in this static...
|
by: truckaxle |
last post by:
I am trying to pass a slice from a larger 2-dimensional array to a
function that will work on a smaller region of the array space. The
code below is a distillation of what I am trying to...
|
by: dkarthik |
last post by:
Hello All,
I am a newbie to C++. I was trying a sample program from internet which
demonstrates dynamic class loading in C++. Actually, I thought of using
this design, in one of the applications...
|
by: nirnimesh |
last post by:
I'm intercepting a library function call using LD_PRELOAD and in-turn
calling the orignial library function. Essentially,
intercept.cc:
void (*real_func)(void) = (void (*) (void))...
|
by: Ivan Liu |
last post by:
Hi,
I'd like to ask if passing an object as an pointer into a function
evokes the copy constructor.
Ivan
|
by: John |
last post by:
Is the following program print the address of the function?
void hello()
{ printf("hello\n");
}
void main()
{
printf("hello function=%d\n", hello);
}
|
by: TS |
last post by:
I was under the assumption that if you pass an object as a param to a method
and inside that method this object is changed, the object will stay changed
when returned from the method because the...
|
by: etienne |
last post by:
Hello all,
i'm experimenting a problem in trying to cast a char * variable to a
pointer to a function.
My problem is that I want to execute functions in threads, using the
pthread_create...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |