Is there an 'easy' way to convert 32Bit code to 64Bit code. I have this benchmark i need to run on different machines and it would be nice if i could run it on the 64 bit machines ass wel.
The output when compiling(1) and running(2) are the following:
(1)
linux:/home/user1/subbench/heapsort # make
gcc -DUNIX -O2 heapsort.c -o heapsort
heapsort.c: In function `main':
heapsort.c:85: warning: return type of `main' is not `int'
heapsort.c: In function `HSORT':
heapsort.c:207: warning: cast to pointer from integer of different size
(2)
linux:/home/user1/subbench/heapsort # ./heapsort
Heap Sort C Program
Version 1.0, 04 Oct 1992
Size of long (bytes): 8
Array Size RunTime Scale MIPS
(bytes) (sec)
16000 0.0003 0.4202 1250.89
32000 0.0007 0.9087 1264.42
64000 0.0015 1.9536 1302.59
128000 0.0032 4.1799 1311.54
Segmentation fault
There is no "easy" (as in automatic) way to fix this. You will need to inspect the code and fix it. How hard that is depends on how badly it is broken. Well written code would generally simply recompile without error upon a move from 32 to 64 bit. When code is not written in a portable manner, it can actually fail if you move it from one 32 bit environment to another 32 bit environment.
long iter,iran,ia,ic,im,ih,ir;
unisgned long msize=0;
.....
msize = m * sizeof(long);
size = m - 1;
base = malloc(msize);
will get rid of the warning.
FWIW - the GNU qsort v routine which is part of standard C on Linux (glib 2.3.3) is probably about 10 times faster than this heapsort, except possibly for very special applications.
In other words you could replace all this with about 10 lines of C if you don't need portability. It looks like it was written to run under several compilers - so a rewrite may not work for you.
What happens when you need to compile for yet another platform or OS? You add another ifdef/else combination making the code more ureadable and harder to maintain.