Sujet : Re: `atomic_fetch_add` on pointer types?
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.cDate : 28. Dec 2024, 05:12:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vkntr0$4rui$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 12/27/2024 2:28 PM, Andrey Tarasevich wrote:
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);
}
Try making it an uintptr_t?
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?
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?
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"?