Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Is this defined behavior? Date: Sat, 03 Feb 2024 00:44:15 -0800 Organization: A noiseless patient Spider Lines: 21 Message-ID: <8634ua9bts.fsf@linuxsc.com> References: <7h8vN.323427$xHn7.112429@fx14.iad> <8734uaq19p.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: dont-email.me; posting-host="86b83c500004563f07cda2ade1e7584b"; logging-data="3221634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jf25+ExO5PW6ncmDnI6DxV26s0QkSthE=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:hyxLtGkCCfuga/ztKBP9pDZOzqE= sha1:6Xye80PZ4TX48h8T8C4DBBNguM0= Xref: csiph.com comp.lang.c:381661 Keith Thompson writes: > Anthony Cuozzo 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.