Yes, I wrote a test fortran77 code which calls mallocf, here are both codes and a makefile:
Code:
</bigscr/TEMP/temp_FC> cat testProgram.f
program test
integer MAX,BYTES_PER_INT
parameter(MAX=5,BYTES_PER_INT=8)
pointer(lptr,link)
integer link(*)
integer i,j
integer mallocf
external mallocf
lptr=mallocf(MAX*BYTES_PER_INT)
do i=1,MAX
link(i)=i+1
end do
do i=1,MAX
write(*,*) 'i= ',i,'link(i)= ', link(i)
end do
stop
end
Code:
(some minor modification from the original)
</bigscr/TEMP/temp_FC> cat mmsc.c
#include<stdlib.h>
long int mallocf(long int *nwords);
long int mallocf_(long int *nwords)
{
long int iptout;
long int nbytes;
long int *p;
nbytes = (*nwords);
if(!(p= (long int *)malloc(nbytes))) {
printf("MALLOCF: Out of memory.\n");
exit(1);
}
iptout=(int)p;
return iptout;
}
Code:
</bigscr/TEMP/temp_FC> cat makefile (written for SUN 64-bit)
FCompiler=f90
FLinker=f90
FCflags= -g -xarch=v9a -xtypemap=integer:64
FLflags= -g -xarch=v9a -xtypemap=integer:64
CCompiler=cc
CCflags=-g -xarch=v9a
Objects=testProgram.o mmsc.o
Program=testProgram
$(Program): $(Objects)
$(FLinker) $(FLflags) -o $@ $(Objects)
testProgram.o: testProgram.f
$(FCompiler) $(FCflags) -c $@ testProgram.f
mmsc.o: mmsc.c
$(CCompiler) $(CCflags) -c $@ mmsc.c
clean:
rm -f $(Objects)
The current code still crashed at the first time link() is assigned a value.
However, I'm not a computer scientist (never looked at assembly codes before, but might try to figure out). The same flag is used for fotran f90 compiler for 64 bit. Using the 64-bit flag, the size of long,long int, long int * and void * are 8 bytes, doubling the 32-bit eqivalents.
</bigscr/TEMP> cc -xarch=v9a foo.c -o foo
</bigscr/TEMP> ./foo
char is 1 bytes
short is 2 bytes
int is 4 bytes
long is 8 bytes
long int is 8 bytes
long long is 8 bytes
long int * is 8 bytes
void pointer is 8 bytes
</bigscr/TEMP> cc foo.c -o foo
</bigscr/TEMP> ./foo
char is 1 bytes
short is 2 bytes
int is 4 bytes
long is 4 bytes
long int is 4 bytes
long long is 8 bytes
long int * is 4 bytes
void pointer is 4 bytes