Solved

parameter passing to dynamically linked library function

Posted on 2003-11-14
6
263 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:Kdo
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now