I have code on two VMWare Virtual Machines. One is a 32 Bit Centos 7 Virtual Machine. The second is a 64 Bit RHEL 7 Virtual Machine. The code runs beautifully on the 32 Bit machine.
I’m having trouble doing a second assignment in C code. In another place within the Fortran 64 Bit code, I removed all but one of several identical consecutive assignments and the segmentation error was removed. What do I do about the below segmentation error? (The second argument in the call to the C routine is an integer, but the C code treats it like a struct pointer!)
[1](RUN TIME OUTPUT) 32 bit Virtual Machine Centos Version 7:
File abc.c function abc_ before assignment MY_ADDRESS =134857380 and my_address = 134857376
File abc.c function abc_ before assignment *MY_ADDRESS =686219592 and my_address->my_value = 10609
File abc.c function abc_ after assignment
File abc.f Calling ABC with Arguments:
File abc.f Calling ABC with MY_ADDRESS = 686219592 and MyInt =
File abc.f 1 MY_ADDRESS + MyInt * 4= 686219596
File abc.c function abc_ before assignment MY_ADDRESS =-1078281524 and my_address = 134742364
File abc.c function abc_ before assignment *MY_ADDRESS =686219596 and my_address->my_value = 0
File abc.c function abc_ after assignment
[2](RUN TIME OUTPUT) 64 bit Virtual Machine RHEL Version 7:
File abc.c function abc_ before assignment MY_ADDRESS =6693860 and my_address = 6693856
File abc.c function abc_ before assignment *MY_ADDRESS =553637392 and my_address->my_value = 10609
File abc.c function abc_ after assignment
File abc.f Calling ABC with Arguments:
File abc.f Calling ABC with MY_ADDRESS = 553637392 and MyInt =
File abc.f 1 MY_ADDRESS + MyInt * 4= 553637396
File abc.c function abc_ before assignment MY_ADDRESS =477741372 and my_address = 4482680
File abc.c function abc_ before assignment *MY_ADDRESS =553637396 and my_address->my_value = 0
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
[3]File abc.f
INTEGER VALUE,MYInt,N,MY_ADDRESS
…
C MY_ADDRESS = …
DO 14 MyInt=VALUE+1,N
print *,'File abc.f Calling ABC with Arguments:'
print *,'File abc.f Calling ABC with MY_ADDRESS = ', MY_ADDRESS,' and MyInt = '
print *,’File abc.f’, MyInt,' MY_ADDRESS + MyInt * 4=',MY_ADDRESS+MyInt*4
CALL ABC (MY_ADDRESS + MyInt * 4, 0)
14 CONTINUE
[4]File abc.c
struct BIG_CHANCE {
int my_value;
};
int abc_(MY_ADDRESS,my_address)
register struct BIG_CHANCE **MY_ADDRESS,*my_address;
{
printf ("File abc.c function abc_ before assignment MY_ADDRESS =%d and my_address = %d\n",MY_ADDRESS,my_address);
printf ("File abc.c function abc_ before assignment *MY_ADDRESS =%d and my_address->my_value = %d\n",*MY_ADDRESS,my_address->my_value);
(*MY_ADDRESS)->my_value=my_address->my_value;
printf ("File abc.c function abc_ after assignment\n");
return;
}
[5]Compilation of C file:
cc -DLINUX -I../include -g -c -o abc.o abc.c
[6]Compilation of Fortran file:
gfortran -g -fno-second-underscore -c abc.f