Are members in a c++ class guaranteed be contiguous?
问题 Are class members in c++ guaranteed to be contiguous? I've tried running the following code with almost all popular c++ compilers, and all of them yield the result 4, which is the relative address of the variable y. Is that a coincidence, or is it guaranteed by the language specifications to be this way? Isn't it possible that the compiler will not make the members x and y contiguous with the class basic address/ contiguous with each other? Please note that this thread does not answer this