C++ Logo

std-discussion

Advanced search

Re: Implicit object creation, arrays, and non-implicit lifetime objects

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Fri, 26 Mar 2021 05:28:06 +0300
On 26/03/2021 05:18, Jason McKesson via Std-Discussion wrote:
> But what does `malloc` return?
>
> According to the standard, it returns a "pointer to a suitable created
> object". But the only object that was created was a `T[10]`, not the
> `T`s themselves.

https://timsong-cpp.github.io/cppwp/n4861/intro.object#12.example-1 says:
> struct X { int a, b; };
> // The call to std​::​malloc implicitly creates an object of type X
> // and its subobjects a and b

I think the same may apply to the `T[10]` case: `T[10]` and its elements are created (but only the lifetime of `T[10]` is started). So malloc can return a pointer to `T[0]`.

But I'm not sure this is 100% true.

Received on 2021-03-25 21:28:09