All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
Segmentation fault (core dumped)
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
Segmentation fault (core dumped) - Sep. 18, '06, 3:09:00 AM
|
|
|
heavy_metal_evil
Posts: 1
Joined: Sep. 17, '06,
Status: offline
|
Hello,
I have a problem, i'm using the C shell of SFU 3.5 with windows XP. I'm trying to link an object file with a fortran file but i a have the message: Segmentation fault (core dumped), Why? What's wrong or missing?
Here is the C script ( i use gcc -c -g -O1 file.c):
#include <stdio.h>
#include <malloc.h>
falloc_(number,e_type,ptr,total,index,addr)
long int *number;
long int *e_type;
long int *ptr;
long int *total;
long int *index;
long int *addr;
{
/* some local variables */
unsigned amount; /* the total number of bytes allowed */
long int *new_space; /* the location of the new space */
unsigned e_size; /* the number of bytes for the element type */
unsigned ayuda;
ayuda=1;
/* return if 0 bytes are asked for */
if ((*number) == 0) {
*index = 1;
*addr = *ptr;
return;
}
if (*e_type == 0) {
e_size = 8;
}
else if (*e_type == 1) {
e_size = 4;
}
else if (*e_type == 2) {
e_size = 4;
};
/* we always allocate one more element than necessary to allow */
/* for alignment problems */
amount = ((*number)+1)*e_size;
/* update the total */
(*total) = (*total) + amount;
amount = ((*number)+1)*ayuda;
/* allocate the new space */
new_space = (long int *) calloc(amount,e_size);
/* check to see if we got the space */
if (new_space == (long int *)NULL)
{
printf("ERROR: Error allocating memory\n");
printf("REMEDY: Not enough memory on system for the problem\n");
exit(-1);
}
/* put the address of the new space in addr */
(*addr) = (long int) new_space;
/* calculate the index */
(*index) = ((((long int)new_space)-((long int)ptr)+e_size)/e_size)+1;
}
And my fortran source code is (i use the command g77 ej.f file.o):
program constvar
CALL FALLOC(6,1,1,1,1,1)
print*,"Hello "
end
Please help!!!!!!
|
|
|
RE: Segmentation fault (core dumped) - Sep. 18, '06, 3:49:01 PM
|
|
|
Rodney
Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
I took what you posted and got this as a result:
> gcc -c -g -O1 file.c
> g77 ej.f file.o
ej.f:1:
program constvar
^
Invalid first character at (^) [info -f g77 M LEX]
ej.f:3:
print*,"Hello "
^
Invalid first character at (^) [info -f g77 M LEX]
ej.f:4:
end
^
Invalid first character at (^) [info -f g77 M LEX]
I'm not a Fortran program, but I'd like to try to replicate your problem.
|
|
|
RE: Segmentation fault (core dumped) - Sep. 18, '06, 5:04:35 PM
|
|
|
Rodney
Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> Kids these days!
Last I did any Fortran was over 20 years ago!
The machine then didn't need that spacing (it was a DEC/VMS
machine if I recall right; similar to the DEC COBOL spacing).
Heck, the Fortran joke about it being a dead language had barely begun :-)
Anyway, thank for the pointer.
The code now compiles with no SEGV during compilation/linking.
This leads me to think that it may be a DEP probelm.
Refer to the FAQ entry for turning DEP off.
Then give it another try.
|
|
|
RE: Segmentation fault (core dumped) - Sep. 18, '06, 5:32:53 PM
|
|
|
eperea
Posts: 70
Joined: Apr. 6, '05,
Status: offline
|
I turned DEP off some time ago, but can duplicate the OP's results:
% gcc -c -g -O1 file.c
% g77 ej.f file.o
% a.out
Segmentation fault (core dumped)
%
|
|
|
RE: Segmentation fault (core dumped) - Sep. 18, '06, 9:53:59 PM
|
|
|
markfunk
Posts: 669
Joined: Mar. 31, '03,
Status: offline
|
from gdb:
quote:
Program received signal SIGSEGV, Segmentation fault.
falloc_ (number=0x40400c, e_type=0x404008, ptr=0x404008, total=0x404008,
index=0x404008, addr=0x404008) at file.c:46
46 (*total) = (*total) + amount;
|
|
|
RE: Segmentation fault (core dumped) - Sep. 19, '06, 4:31:25 AM
|
|
|
spahlinger
Posts: 28
Joined: Jul. 9, '04,
Status: offline
|
Your FORTRAN program calls FALLOC with a list of constant parameters: CALL FALLOC(1,1,1,1,1,1). These parameters are given to the c program by refeference, which in turn tries to change these arguments. But this is not allowed, because these are constants. If you change your FORTRAN code to
program constvar
i=6
j=1
k=1
l=1
m=1
n=1
CALL FALLOC(i,j,k,l,m,n)
print*,"Hello " ,i,j,k,l,m,n
end
you will see what happens. The result would be:
Hello 6 1 1 29 21319 8604752
As can be seen, the last three parameters have been modified, meaning that it is invalid to use contants here.
By the way, I think that it is also invalid to use calloc or printf in the c program, because when linking with g77 (instead of gcc) the gcc-specific initialization routines for heap menagement and io-handling are not performed.
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|