'void *' : unknown size compilation error


medovikov
06-03-2002, 01:44 PM
I have 'void *' : unknown size compilation error
in line

return v - size*(nl-NR_COMPATIBLE);

I use Visual C++. This line is OK for g++ compilers because
it uses char * instead of void * (as far as I know).
What should be done to avoid this error in Visual C++?

Thanks.




/*
* memory allocator for any type of vector, matrix, tensor < vmtlib.c >
*
* VMT: Vector Matrix Tensor lib, Numerial Recipes in C compatible
*
* Copyright (C) 1999 Taiji Yamada
*/

void *(vector_alloc)(size_t size, long nl, long nh)
{
void *v = malloc(size*(nh-nl+1+NR_COMPATIBLE));
if (!v)
return NULL;
else
return v - size*(nl-NR_COMPATIBLE); //THIS LINE
}

medovikov
07-16-2002, 08:01 PM
It looks like the best solution is to perform type conversion
explicitly
Instead of:

return v - size*(nl-NR_COMPATIBLE);

Use

return (void*) ((char*) v - size*(nl-NR_COMPATIBLE));