4 ms·
> Can C begin the lifetime of a C++ object? Yes. C++14 Standard §3.8p1: ...An object is said to have non-vacuous initialization if it is of a class or aggrega
by Kristine1975 11y ago
> Can C begin the lifetime of a C++ object?
Yes. C++14 Standard §3.8p1:
...An object is said to have non-vacuous initialization if it is of a class or aggregate type and it or one of its members is initialized by a constructor other than a trivial default constructor... The lifetime of an object of type T begins when:
— storage with the proper alignment and size for type T is obtained, and
— if the object has non-vacuous initialization, its initialization is complete.
Since class "C" is standard-layout and has a trivial default constructor (in this case none at all), assuming that malloc allocates memory that is suitably aligned for "C", the function make_s returns a pointer to an instance of C++ class "C" whose lifetime has begun.
Edit: Thanks for asking btw. I use similar code in a project of mine but never actually checked whether it is actually standard-conforming.