Solved

parameter passing to dynamically linked library function

Posted on 2003-11-14
6
266 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

770 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