Folks
I am trying to understand if there is any thing in the following piece of code that will cause it to fail on 64 bit platforms. My main concern is whether some type conversions are happening that are not suitable for 64 bit. Do not pay too much attention on the actual numbers assigned to the variables as i made them up just for this example. My main concern is the type conversion issues happening between long and int and size_t
and any other issues you may see.
#define NL_AREA 40
#define NS_AREA 38
#define NB_EXTRA (1536 - NS_AREA * NL_AREA)
main()
{
long int bufsize;
int obssize, nelm, nbuf;
int ncol, ndet = 10;
void *result;
obssize = xxx; /* some size */
bufsize = (long)obssize * (NL_AREA * NS_AREA + NB_EXTRA);
ncol = 50;
nbuf = ncol * ndet;
nelm = 1;
result = Buf_Init(bufsize, nelm, nbuf);
}
void *
Buf_Init( size_t elm_size,
int nelm_buf,
long nbuf )
{
long buf_size;
void *p;
buf_size = ((long) elm_size) * nelm_buf;
if ((p = (void *)malloc(buf_size)) == NULL)
return NULL;
else
return p;
}