From: adr <adr@SDF.ORG>
To: 9fans <9fans@9fans.net>
Subject: Re: [9fans] void*
Date: Sun, 15 May 2022 15:49:13 +0000 (UTC) [thread overview]
Message-ID: <249582cc-285-c02-7779-ccc21b7a7267@SDF.ORG> (raw)
In-Reply-To: <93C8C37CBACFF2EA1B7D96EF381C93E4@eigenstate.org>
On Sun, 15 May 2022, ori@eigenstate.org wrote:
>> On Sun, 15 May 2022, arnold@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
next prev parent reply other threads:[~2022-05-15 15:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-15 10:58 adr
2022-05-15 12:11 ` Humm
2022-05-15 13:03 ` adr
2022-05-15 13:15 ` adr
2022-05-15 13:21 ` arnold
2022-05-15 14:09 ` adr
2022-05-15 14:47 ` ori
2022-05-15 15:49 ` adr [this message]
2022-05-15 15:23 ` Dan Cross
2022-05-15 15:50 ` Bakul Shah
2022-05-15 15:54 ` ori
2022-05-15 14:46 ` ori
2022-05-15 16:07 ` adr
2022-05-16 6:24 ` Skip Tavakkolian
2022-05-16 12:46 ` Humm
2022-05-16 13:23 ` Bakul Shah
2022-05-16 14:46 ` Charles Forsyth
2022-05-16 16:03 ` adr
2022-05-16 17:45 ` hiro
2022-05-17 4:00 ` Lucio De Re
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=249582cc-285-c02-7779-ccc21b7a7267@SDF.ORG \
--to=adr@sdf.org \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).