On Sun, 15 May 2022, o...@eigenstate.org wrote:
On Sun, 15 May 2022, arn...@skeeve.com wrote:

It allows you pass pointers of any type without requiring casts:

       struct foo s[5] = ...
       memmove(s, & s[1], 4 * sizeof(struct foo));     // shift down 1

The compiler won't complain because any pointer type can be passed
to a void* parameter.  Otherwise you'd need to cast:

       memmove((uchar*) s, (uchar*) & s[1], 4 * sizeof(struct foo));

Sure, but you could change it to do the same with char*.


char* has legitimate uses for things other than generic pointers,
and the conversion complaints catch bugs.

My point here is that It makes more sense to me to use a generic
pointer which have a size (the type it points) of 1, so arithmetic
can be applied to it. Of course I'm not proposing to change the
compiler and all the code. It was just a reflection. Allowing
arithmetic on void* solves the problem. Reading the definition of
void this could look incongruous, but C99 already specifies:

"A pointer to void shall have the same representation and alignment 
requirements as a
pointer to a character type"

So I don't see any real trouble to allow the same operations as with char*.

Again, just some thoughts. The comments about uchar* or uint8* are
because arithmetic on void* brakes the concept of void, I don't
really like it.  But sometime things are doomed to staid as they
are, even if they don't make sense...

adr.

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tecaea3b9ec8e7066-M7092e86f1d4c6f710af49d81
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to