Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of atomic types

Tags:

c++

Does the standard say that sizeof(std::atomic<T>) is equal to sizeof(T)?

(I'm investigating building union of atomic and other types for use across an ABI that ideally should not have STL types. If the sizes are identical then this could work).

like image 303
P45 Imminent Avatar asked Oct 02 '14 15:10

P45 Imminent


1 Answers

[atomics.types.generic]/p9

Note: The representation of an atomic specialization need not have the same size as its corresponding argument type. Specializations should have the same size whenever possible, as this reduces the effort required to port existing code

No, you can't assume that. It's a best-effort endeavor but no guarantees.

like image 136
Marco A. Avatar answered Oct 18 '22 06:10

Marco A.