uses of void
Tom Stockfisch
tps at sdchem.UUCP
Mon Aug 11 11:22:12 AEST 1986
I want to be able to use "void *" in a generic sorting function and I tried
something like
sort( (void *)&foo[0], (void *)&foo[20], sizeof(foo), compare_foos );
.
.
.
void
sort( beg, end, size, compare )
void *beg, *end;
int size;
int (*compare)();
{
int nelements = (end - beg) / size;
for ( p = beg; p < end; p += size )
...;
...
}
My compiler (4.2BSD running on a Celerity) when into an infinite loop trying
to parse
(end - beg)
I (naively?) thought that pointer arithmetic would work with "void *", and
that it would work in the same abstract units as "sizeof()", so that all
previous generic "char *" kludges could be replaced by "void *".
What are the (proposed and current) legal operations for "void *" besides
assignment, casting, and passing as a parameter?
-- Tom Stockfisch, UCSD Chemistry
--
-- Tom Stockfisch, UCSD Chemistry
More information about the Comp.lang.c
mailing list