Segmentation fault (core dumped) (Full Version)

All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum



Message


heavy_metal_evil -> Segmentation fault (core dumped) (Sep. 18, '06, 3:09:00 AM)

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!!!!!!




Rodney -> RE: Segmentation fault (core dumped) (Sep. 18, '06, 3:49:01 PM)

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.




eperea -> RE: Segmentation fault (core dumped) (Sep. 18, '06, 4:15:37 PM)

Kids these days! [:D]

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.




Rodney -> RE: Segmentation fault (core dumped) (Sep. 18, '06, 5:04:35 PM)

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




eperea -> RE: Segmentation fault (core dumped) (Sep. 18, '06, 5:32:53 PM)

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)
%




markfunk -> RE: Segmentation fault (core dumped) (Sep. 18, '06, 9:53:59 PM)

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;




spahlinger -> RE: Segmentation fault (core dumped) (Sep. 19, '06, 4:31:25 AM)

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.




Page: [1]



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.031