function receives value that I didn't pass in

M

Markus Dehmann

I have a strange problem. My program segfaults, and when I use the
debugger I find that a function that I call with a parameter int n=1
is actually executed with a garbled parameter int n=136857236. So the
function does not receive the actual value that I pass in, but works
with some messed-up value.

What might be the reason for this? The called function is defined in
another .o file. So I thought the reason might be that the .o file is
compiled with different settings, but that doesn't seem to be the
case. Are there other possible reasons for such a strange behavior?

Thanks!
Markus
 
K

Kenneth Doyle

I have a strange problem. My program segfaults, and when I use the
debugger I find that a function that I call with a parameter int n=1
is actually executed with a garbled parameter int n=136857236. So the
function does not receive the actual value that I pass in, but works
with some messed-up value.

What might be the reason for this? The called function is defined in
another .o file. So I thought the reason might be that the .o file is
compiled with different settings, but that doesn't seem to be the
case. Are there other possible reasons for such a strange behavior?
Possibly, you're passing the address of n and not the value?
 
R

Ramsey Stone

Possibly, you're passing the address of n and not the value?

This is likely the culprit. Alternatively, is the integer you're
passing a reference to another integer?
 
J

Jim Langston

Ramsey said:
This is likely the culprit. Alternatively, is the integer you're
passing a reference to another integer?

Another possibility is stack corruption. It could happen in the call to the
fuction, or before somewhere. Or possibly after when you check the value
the stack has already been corrupted.
 
P

Puppet_Sock

I have a strange problem.
[snip]

Indeed you do. Since you didn't post any code, it's pretty
much impossible to diagnose your problem.

Have you read the FAQ on how to post? And the parts about
how to get other people to debug your code? Please do that
before posting more on this.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top