Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

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
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> Segmentation fault (core dumped) Page: [1]
Login
Message << Older Topic   Newer Topic >>
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!!!!!!
Post #: 1
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.

(in reply to heavy_metal_evil)
Post #: 2
RE: Segmentation fault (core dumped) - Sep. 18, '06, 4:15:37 PM   
eperea

 

Posts: 70
Joined: Apr. 6, '05,
Status: offline
Kids these days!

I imagine g95 would have no problem with it, but if it's g77 you have to remember that all these lines need to start on column 7. Other than comments, columns 1-5 are for numeric labels and column 6 for line continuation characters. (Start counting with 1, not 0.)

I imagine g77 has a switch to allow free-form syntax, but I don't know what it is.

(in reply to Rodney)
Post #: 3
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.

(in reply to eperea)
Post #: 4
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)
%

(in reply to Rodney)
Post #: 5
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;

(in reply to eperea)
Post #: 6
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.

(in reply to markfunk)
Post #: 7
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> Segmentation fault (core dumped) Page: [1]
Jump to:





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


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.063