Solved

parameter passing to dynamically linked library function

Posted on 2003-11-14
6
262 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 how to use strings and some functions related to them in the C programming language.

757 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

23 Experts available now in Live!

Get 1:1 Help Now