Solved

parameter passing to dynamically linked library function

Posted on 2003-11-14
6
267 Views
Last Modified: 2010-05-18
Hi all,

In my C program, I access a function from a dynamically linked library (.so) . The problem I am facing is that the values of the arguments that I passed in my C program are not the parameter values that I receive in the linked library function. I checked this using gdb. I don;t understand why this is happening. Any clues? If it helps, I compile my program using gcc whereas the library was compiled using g++.
0
Comment
Question by:blizkreeg
6 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9752049

This sounds like a "passed by value" vs "passed by reference" issue.

Are you sure that you're passing the correct types?

Kent
0
 

Author Comment

by:blizkreeg
ID: 9752132
yes, there is no problem with the parameter types

can it be something related to the calling conventions? if so, and if you have knowledge about it please let me know
0
 
LVL 2

Expert Comment

by:jscase
ID: 9752852
What operating system? Are you linking to a C++ library from a C program? How do you know there is no problem with the parameter types?

jsc
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 9752976
Hi blizkreeg

try printing the parameters ... there could be a number of reasons why you are seeing things differently in gdb ... I learn't it the hard way ;o)

gdb generally keeps your parameters in registers... As control flow proceeds, it moves things around and whenever you ask for value, it still prints the contents of the registers... though your value is actually safe and somewhere else... I know its weird but it happened with me .... try printing the address of your variable/parameter ... Most likely it would say "referencing address of XXX which is a register value" or something similar

another highly likely reason could be that you have not formed your parameters correctly, or there is a memcpy, strcpy or something which you are assuming safe ....

If the above two things do not fit, the bill, post you code here and we will try to pin point the reason

Sunny
0
 
LVL 22

Expert Comment

by:grg99
ID: 9754035
What does the function prototype in the calling code, and the one in the called code look like?

They have to be IDENTICAL in all respects.

0
 

Author Comment

by:blizkreeg
ID: 9781550
Problem solved. you were right sunnycoder....I was relying on the values gdb showed which were not the real values. I was actually getting the correct parameter values in the called function.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question