Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #381617
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Is this defined behavior? |
| Date | 2024-02-02 08:28 -0800 |
| Organization | None to speak of |
| Message-ID | <8734uaq19p.fsf@nosuchdomain.example.com> (permalink) |
| References | <7h8vN.323427$xHn7.112429@fx14.iad> |
Anthony Cuozzo <anthony@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.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Is this defined behavior? Anthony Cuozzo <anthony@cuozzo.us> - 2024-02-02 10:56 -0500
Re: Is this defined behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-02-02 08:28 -0800
Re: Is this defined behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-02-03 00:44 -0800
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-03 16:07 +0000
Re: Is this defined behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-02-03 13:41 -0800
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-04 03:18 +0000
Re: Is this defined behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-02-03 19:48 -0800
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-04 04:34 +0000
Re: Is this defined behavior? David Brown <david.brown@hesbynett.no> - 2024-02-04 13:24 +0100
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-04 15:16 +0000
Re: Is this defined behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-02-04 13:31 -0800
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-04 23:18 +0000
Re: Is this defined behavior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-02-04 15:56 -0800
Re: Is this defined behavior? gazelle@shell.xmission.com (Kenny McCormack) - 2024-02-05 00:05 +0000
Re: Is this defined behavior? Poprocks <please@replytogroup.com> - 2024-02-05 13:35 -0500
Re: Is this defined behavior? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-06 13:10 +0000
Is this sane behavior? (Was: Is this defined behavior?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-02-06 14:52 +0000
Re: Is this sane behavior? (Was: Is this defined behavior?) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-02-06 15:50 +0000
Re: Is this defined behavior? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-02-04 23:21 -0800
Re: Is this defined behavior? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2024-02-04 15:27 +0000
Re: Is this defined behavior? David Brown <david.brown@hesbynett.no> - 2024-02-04 18:23 +0100
csiph-web