Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #389825
| Path | csiph.com!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: `atomic_fetch_add` on pointer types? |
| Date | Tue, 31 Dec 2024 06:08:31 -0800 |
| Organization | A noiseless patient Spider |
| Lines | 50 |
| Message-ID | <868qrwaqsg.fsf@linuxsc.com> (permalink) |
| References | <vkn9lk$3rtdm$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Date | Tue, 31 Dec 2024 15:08:35 +0100 (CET) |
| Injection-Info | dont-email.me; posting-host="e21c1894af35152a2f46a9d8fe234703"; logging-data="2394223"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ATOM8TxxP43UuH/l6ZPto0ncZ9uF9Hok=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:watUlDngLSVMI4Iv+N0hOImbXxg= sha1:Uzzo/v4T0U+U+oBxTPLcOBVFN2M= |
| Xref | csiph.com comp.lang.c:389825 |
Show key headers only | View raw
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
[some whitespace in quoted text was modified]
> The code
>
> #include <stdatomic.h>
> #include <stdio.h>
>
> int main()
> {
> int v[2], *_Atomic p = v;
> atomic_fetch_add(&p, 1);
> printf("%tu\n", (char *) p - (char *) v);
> }
>
> GCC prints 1 (https://godbolt.org/z/55Pjcnd3Y), while Clang prints 4
> (https://godbolt.org/z/e4x6z85fe). Obviously, Clang performed the
> "proper" pointer arithmetic, while GCC ignored the pointer type.
>
> Which one is correct here?
The behavior shown by clang is obviously the more sensible choice.
The C standard is not as clear on this point as I would like it to
be, but I believe the behavior shown by clang is what was intended.
> 7.17.7.5 says (https://port70.net/~nsz/c/c11/n1570.html#7.17.7.5)
>
> 1 The following operations perform arithmetic and bitwise
> computations. All of these operations are applicable to an
> object of any atomic integer type. None of these operations
> is applicable to atomic_bool.
>
> Is this wording intended to restrict these operations to integer
> types only?
I believe it was not; otherwise there is no point to the paragraph
you mention next. See also below.
> But later 7.17.7.5 also says
>
> 3 For address types, the result may be an undefined address, but
> the operations otherwise have no undefined behavior.
>
> However, I was unable to find any mention of "address types" anywhere
> else in the standard. This is the only spot in the entire document
> mentioning "address types". What types are "address types"?
Surely "address types" should be taken as being synonymous with
"pointer types". More details to follow in comp.std.c.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar
`atomic_fetch_add` on pointer types? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-12-27 14:28 -0800 Re: `atomic_fetch_add` on pointer types? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-12-27 17:43 -0800 Re: `atomic_fetch_add` on pointer types? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-12-27 20:12 -0800 Re: `atomic_fetch_add` on pointer types? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-12-31 06:08 -0800
csiph-web