Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is this defined behavior?

92 views
Skip to first unread message

Anthony Cuozzo

unread,
Feb 2, 2024, 10:57:07 AMFeb 2
to
Time T: Add N to a uintptr_t

Time T+1: Subtract N from that same uintptr_t

Questions:

1. Is this behavior defined?

2. If it is, then will I be guaranteed to get back the same void * value
I cast to uintptr_t?

Thank you,
--Anthony

Keith Thompson

unread,
Feb 2, 2024, 11:28:18 AMFeb 2
to
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.

> 2. If it is, then will I be guaranteed to get back the same void *
> value I cast to uintptr_t?

If the result of the conversion is a valid pointer value, yes. In
particular, if the original value is the result of converting a valid
void* value, the guarantee in the standard applies:

The following type designates an unsigned integer type with the
property that any valid pointer to void can be converted to this
type, then converted back to pointer to void, and the result will
compare equal to the original pointer:

uintptr_t

Adding and subtracting N between the conversions is well defined.

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Tim Rentsch

unread,
Feb 3, 2024, 3:44:32 AMFeb 3
to
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.

Malcolm McLean

unread,
Feb 3, 2024, 11:07:49 AMFeb 3
to
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.

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.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Keith Thompson

unread,
Feb 3, 2024, 4:41:25 PMFeb 3
to
What on Earth are you talking about?

Malcolm McLean

unread,
Feb 3, 2024, 10:18:54 PMFeb 3
to
On 03/02/2024 21:41, Keith Thompson wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
>> 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.
>>
>> 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.
>>
>> 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.
>
> What on Earth are you talking about?
>
It's objectively the case that this sort of post gives the ng a bad
reputation. But we don't necessarily have to care what other people
think. So I'm not criticising Tim for this. I'm not saying that the post
should not have been made. I'm not taking a position.

But the issue of sort of material we wish to see has been raised, and as
regular contributor myself, I'm interested in what other people think.
Is this the sort of material you wish to see? I'm interested in views.
Including yours.

Keith Thompson

unread,
Feb 3, 2024, 10:49:02 PMFeb 3
to
Nonsense.

[snip more nonsense]

Malcolm McLean

unread,
Feb 3, 2024, 11:34:25 PMFeb 3
to
Bless.
You've been invited to give your view. If you won't do so, I hope you
won't blame me if therefore your views don't count.

David Brown

unread,
Feb 4, 2024, 7:24:24 AMFeb 4
to
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.

Malcolm McLean

unread,
Feb 4, 2024, 10:17:09 AMFeb 4
to
On 04/02/2024 12:24, David Brown wrote:
>
> You /have/ taken a position, and you /have/ criticised Tim for his post
> - by making this complaint.
>

Other people have made that complaint. I'm not making it myself. But
other people have said this, so it is therefore an issue.

I want other people's views, and thnk you for giving yours.

Ben Bacarisse

unread,
Feb 4, 2024, 10:27:28 AMFeb 4
to
David Brown <david...@hesbynett.no> writes:

> 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.)

I think you are suggesting that uintptr_t might, on such a system, be
only 8 bits wide, but that's no permitted. UINTPTR_MAX can be no less
than 2**16 - 1. Of course that alone does not prevent its rank being
less that that of int, but the system you describe would not be an
example.

--
Ben.

David Brown

unread,
Feb 4, 2024, 12:23:14 PMFeb 4
to
Good point. (Of course, many 8-bit implementations have deviations from
the standards, at least as options - some allow 8-bit "int", for
example. But then we are no longer talking about standard C.)

I have also used a system where the total memory space fit within a 16
bit address range, while the cpu can handle 32-bit data and arithmetic
directly. IIRC, it had a 16-bit "int", but such a system could
reasonably have had 16-bit uintptr_t and 32-bit int. But again, that's
still hypothetical - just not unimaginable.

Keith Thompson

unread,
Feb 4, 2024, 4:32:01 PMFeb 4
to
Malcolm McLean <malcolm.ar...@gmail.com> writes:
> On 04/02/2024 12:24, David Brown wrote:
>> You /have/ taken a position, and you /have/ criticised Tim for his
>> post - by making this complaint.
>
> Other people have made that complaint. I'm not making it myself. But
> other people have said this, so it is therefore an issue.
>
> I want other people's views, and thnk you for giving yours.

You haven't given your views. You've just falsely claimed that it's
"also fair to say that it's the sort of post which gives the newgroup a
bad reputation".

I think you're trying to start an argument while pretending to be above
the fray. I don't know or care why.

If you have something to say about what was wrong with Tim's post,
you're free to say it. If not, please drop this -- and I suggest that
others not take the bait.

Malcolm McLean

unread,
Feb 4, 2024, 6:19:01 PMFeb 4
to
On 04/02/2024 21:31, Keith Thompson wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
>> On 04/02/2024 12:24, David Brown wrote:
>>> You /have/ taken a position, and you /have/ criticised Tim for his
>>> post - by making this complaint.
>>
>> Other people have made that complaint. I'm not making it myself. But
>> other people have said this, so it is therefore an issue.
>>
>> I want other people's views, and thnk you for giving yours.
>
> You haven't given your views. You've just falsely claimed that it's
> "also fair to say that it's the sort of post which gives the newgroup a
> bad reputation".
>
> I think you're trying to start an argument while pretending to be above
> the fray. I don't know or care why.
>
> If you have something to say about what was wrong with Tim's post,
> you're free to say it. If not, please drop this -- and I suggest that
> others not take the bait.
>

I know that this is hard for you because you your psychological type.
But try to step think back and think what the reaction of a perfectly
normal person might be if, coming to the ng for the first time, that was
the first post he read. Then think what other people have said on
related subjects, and whether or not it is an objective reality,
independent of my opinion, whether or not that has been said.

However I am not myself personally either the hypothetical person coming
to the ng for the first time, nor the actual and indisputably existent
person who I am thinking of especially. I'm not the source of the
complaints.

But of course the complaint is that whilst the point made might be true
if you intepret the C stnadard in a literal sense, it is so unlikely
that anyone would implement such a compiler, or even think of doing so,
that it is abusrd. And so the ng does get a bad reputation. Objectively
and not just in my opinion. And whilst I am think especially of one
person, he's not saying something which is eccentric, or not level
headed. But I'm holding judgement on whether that is fair, or if it
matters. If other people hold us in contempt, is that a big issue, if we
enjoy discussing what we discuss?

Tim complained about other people's content, including but not
especially mine. So it's only fair if we now discuss his content.
However I don't want to complain about it. I don't see it as a simple
and open and shut issue like that. And I don't want to antagonise. I
think we've far too much antognistic behaviour going on at the moment
and its time to try to out a stop to it.
--
Check out Basic Algorithms and my other books:
/////
https://www.lulu.com/spotlight/bgy1mm

Keith Thompson

unread,
Feb 4, 2024, 6:56:41 PMFeb 4
to
Malcolm McLean <malcolm.ar...@gmail.com> writes:
[...]
> I know that this is hard for you because you your psychological type.
[...]

Go away.

Kenny McCormack

unread,
Feb 4, 2024, 7:05:51 PMFeb 4
to
In article <87o7cvl...@nosuchdomain.example.com>,
Keith Thompson <Keith.S.T...@gmail.com> wrote:
>Malcolm McLean <malcolm.ar...@gmail.com> writes:
>[...]
>> I know that this is hard for you because you your psychological type.
>[...]
>
>Go away.

Very mature.

And about what we expect from your psychological type.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/RightWingMedia

Tim Rentsch

unread,
Feb 5, 2024, 2:22:16 AMFeb 5
to
Keith Thompson <Keith.S.T...@gmail.com> writes:

>> [... some discussion regarding a posting of mine and alleged
>> reactions to it ...]
>
> If you have something to say about what was wrong with Tim's post,
> you're free to say it. If not, please drop this -- and I suggest
> that others not take the bait.

Thank you for this summary. I second your suggestion.

Poprocks

unread,
Feb 5, 2024, 1:36:05 PMFeb 5
to
On 2024-02-04, Malcolm McLean wrote:
> On 04/02/2024 21:31, Keith Thompson wrote:
[snip]
>> You haven't given your views. You've just falsely claimed that it's
>> "also fair to say that it's the sort of post which gives the newgroup a
>> bad reputation".
>>
>> I think you're trying to start an argument while pretending to be above
>> the fray. I don't know or care why.
>>
>> If you have something to say about what was wrong with Tim's post,
>> you're free to say it. If not, please drop this -- and I suggest that
>> others not take the bait.
>>
>
> I know that this is hard for you because you your psychological type.
> But try to step think back and think what the reaction of a perfectly
> normal person might be if, coming to the ng for the first time, that was
> the first post he read. Then think what other people have said on
> related subjects, and whether or not it is an objective reality,
> independent of my opinion, whether or not that has been said.
[snip]

I'm not exactly coming to this ng for the first time, but I've been a
casual occasional reader at best and am coming back to it after a long
while. The original parent thread was the first thread that looked
interesting to me, and I read it and gained some knowledge.

And then I spent 10 minutes of my life I'll never get back, reading this
bizarre, passive-aggressive flamebait.

*plonk*

Malcolm McLean

unread,
Feb 6, 2024, 8:10:59 AMFeb 6
to
I should point out that meta posts about the newsgroup itself are topical.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Kenny McCormack

unread,
Feb 6, 2024, 9:52:36 AMFeb 6
to
In article <slrnus2ak7...@loganrpi.rathbonelaw.com>,
Poprocks <ple...@replytogroup.com> whined:
...
>And then I spent 10 minutes of my life I'll never get back, reading this
>bizarre, passive-aggressive flamebait.

And then you spent 20 minutes of your life you'll never get back, posting
the above bizarre, passive-aggressive flamebait.

--
'Islamaphobia' is a term created by fascists and used by cowards to manipulate morons.

- Author unknown, quoted by Sam Harris -

Malcolm McLean

unread,
Feb 6, 2024, 10:50:49 AMFeb 6
to
On 06/02/2024 14:52, Kenny McCormack wrote:
> In article <slrnus2ak7...@loganrpi.rathbonelaw.com>,
> Poprocks <ple...@replytogroup.com> whined:
> ...
>> And then I spent 10 minutes of my life I'll never get back, reading this
>> bizarre, passive-aggressive flamebait.
>
> And then you spent 20 minutes of your life you'll never get back, posting
> the above bizarre, passive-aggressive flamebait.
>
It's self refuting. And the use of technical pyschiatric terms they
don't really understand as an insult is very trademark.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

0 new messages