Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parameter passing to dynamically linked library function

Posted on 2003-11-14
6
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 46

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 45

Accepted Solution

by:
sunnycoder earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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 recursion 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.

610 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