32bit to 64bit conversion.

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

The make file and source file can be found here if you want to have a look at it yourself.
http://users.pandora.be/steviewilliams/heapsort.zip
Mind that my knowledge of C is very basic :).
Greetz

Don't declare main as void:

void main()

will not work.
try:

int main(int argc, char *argv[])

instead.

I know that it is better not to declare main as void, but the problem is the other warning I get when compiling on 64 bit.

heapsort.c: In function `HSORT':
heapsort.c:207: warning: cast to pointer from integer of different size

This is responsable for the segmentation error i get when i try to run the program on 64 bit cpu.

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.

try:

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.

#include <inttypes.h>

and use int32_t, int64_t, uint32_t, uint64_t where appropriate.

Avoid the use of a long data types. The problem being when compiled 32bit they are 4 bytes and when compiled 64bit they are 8 bytes.

better to use #ifdef's instead of all these issues

I disagree for the following reasons:

  1. #ifdef makes code harder to read.
  2. You now need to maintain two versions.
  3. 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.