473,498 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Segmentation fault when returning a value on a different PC

Hi.

I've got a C program which calls a function:
----------------
printf("TEST1\n");
int value = my_function(param);
printf("TEST2\n");

int my_function(int my_param)
{
int internal_param = my_array[index];
printf("%d\n", internal_param); //it works ok
return internal_param;
}
-----------------

I compile it ok, and it works on my PC, but when I run it on
another PC, I get this error:
--------------------
TEST1
0
Segmentation fault
--------------------

So it crashes when returning the value. What am I doing wrong? Thank
you very much. Regards.

Nov 14 '05 #1
2 1234
fr**********@europe.com wrote:
I've got a C program which calls a function:
----------------
printf("TEST1\n");
int value = my_function(param);
printf("TEST2\n");

int my_function(int my_param)
{
int internal_param = my_array[index];
printf("%d\n", internal_param); //it works ok
return internal_param;
}
-----------------

I compile it ok, and it works on my PC, but when I run it on
another PC, I get this error:
--------------------
TEST1
0
Segmentation fault
--------------------

So it crashes when returning the value. What am I doing wrong? Thank
you very much. Regards.


Could you give the complete program you are compiling?
Nov 14 '05 #2

francesco...@europe.com wrote:
Hi.

I've got a C program which calls a function:
----------------
printf("TEST1\n");
int value = my_function(param);
printf("TEST2\n");

int my_function(int my_param)
{
int internal_param = my_array[index];
printf("%d\n", internal_param); //it works ok
return internal_param;
}
-----------------

I compile it ok, and it works on my PC, but when I run it on
another PC, I get this error:
--------------------
TEST1
0
Segmentation fault
--------------------

So it crashes when returning the value. What am I doing wrong? Thank
you very much. Regards.

When you have trouble with your car, to take pieces of it in to the
mechanic, or the whole thing? You've shown us a part of your program,
probably not the part actually causing the problem. For instance, we
don't know what my_array, index, or param are. It's particularly
suspicious that you pass param in as an argument to my_param, then
never use my_param in the function.

Post a complete, minimal program that demonstrates the problem.

Brian

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
4453
by: Vishal Grover | last post by:
Hello Everyone, I am seeing a certain behaviour which I find strange, and am curious to get an explanation to it. I have the following program. #include <iostream> #include <cstdlib> using...
16
8956
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
5
1899
by: Ravikant | last post by:
Hello, Please check the following code .Let me know why its giving the segmentation fault while running it.First it asks to enter the name ,when entered it gives segmentation fault. But if I dont...
21
8213
by: user | last post by:
I just finish writing LAB2 with no errors when compiling, but once i run it, i get "segmentation fault".. i don't know what is wrong, can anyoen tell me what it means and how i can fix it? thx!
6
2288
by: damian birchler | last post by:
If I run the following I get a segmentation fault: #define NAMELEN 15 #define NPERS 10 typedef struct pers { char name; int money; } pers_t;
5
1776
by: Verrigan | last post by:
I'm trying to pass an array to a function, and change the values of that array, but I can't seem to figure it out.. Please help me figure out what I'm doing wrong... Any help would be...
2
744
by: Chris Grossbe | last post by:
Hi! this problem has been a headache for about 2 hours now and i just cant figure it out. ive got a c program that connects to a DB via mysql. currently ive got 2 querys. the first worked...
27
3314
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
3
288
by: Anna | last post by:
Could you please help me? I got a segmentation fault message while trying to assign a pointer = pointer like this: bufferlist=(buffer_t*)buffernew; What's the error by doing this? Here is the...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.