On 03/02/2024 17:07, Malcolm McLean wrote:
> On 03/02/2024 08:44, Tim Rentsch wrote:
>> Keith Thompson <
Keith.S.T...@gmail.com> writes:
>>
>>> Anthony Cuozzo <
ant...@cuozzo.us> writes:
>>>
>>>> Time T: Add N to a uintptr_t
>>>>
>>>> Time T+1: Subtract N from that same uintptr_t
>>>>
>>>> Questions:
>>>>
>>>> 1. Is this behavior defined?
>>>
>>> Sure, why wouldn't it be? uintptr_t is just an unsigned integer
>>> type. The guarantees about converting to and from void* don't
>>> affect its arithmetic behavior. Adding and then subtracting N
>>> yields the original value.
>>
>> Extremely likely to hold. A perverse implementation could choose
>> (IIANM) a uintptr_t whose integer conversion rank is less than
>> that of int, and that could mess things up. In practical terms
>> though what you say is spot on.
An 8-bit implementation with very limited RAM might use 8-bit pointers,
at least for "normal" pointers. (Typically such systems also support
extensions such as "far" pointers, or "code memory" pointers.) I
haven't seen such an implementation, but it is certainly conceivable.
("int" would be 16-bit.)
>
> OK, so this is completely topical and there's no issue there. But it's
> also fair to say that it's the sort of post which gives the newgroup a
> bad reputation.
>
No, it is the kind of thing that gives this group a /good/ reputation.
People with questions about C behaviour can come here and ask, and get
considered answers. In particular, they get answers from people who
look carefully at the standards - not just one or two implementations.
They tell you about uncommon situations that others might not have
considered - including uncommon real implementations, and also possible
implementations. For people who want to write code that they /know/
works, and /know/ is correct even if it is used on other platforms, this
kind of information is invaluable.
For people who are happy with "I tried it and it worked on my compiler
on my machine", it is of little interest.
If this newsgroup were filled with nothing but discussions about C
standard minutiae, it would be boring to many people - and yet still a
value resource for people to visit when they need to. But it is not
filled with that - it is an important aspect of the group, but not the
only one.
The validity of pointers as they are converted or arithmetic is applied
is of huge interest, and is a significant area of research in language
design and compiler design. There is a lot of work being done on
"pointer providence" - where pointers come from, and what they can point
to. Knowing what, if anything, they can point to, and whether there
are aliases, is massively relevant to code correctness and optimisation
opportunities for compilers.
If you don't care about any of this, that's fine - skip the thread. But
let the people that do care talk about these things.
> I'm not going to take a position. But since we've had complaints about
> the diection things are going in, other people might like to weigh in on
> this.
>
You /have/ taken a position, and you /have/ criticised Tim for his post
- by making this complaint.