C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] P2174 Status (and a tenuous offer to help)

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Wed, 12 May 2021 23:05:01 +0200
On 12/05/2021 22.38, Charlie Barto wrote:
> If we allow taking the address than the lifetime needs to be longer than the lifetime of the pointer we're assigning it to, that's all.

That's fine. The inner struct is created before the outer struct, so
is destroyed after the outer struct, regardless of whether at end of
full-expression or at end of block.

Jens


> -----Original Message-----
> From: Jens Maurer <Jens.Maurer_at_[hidden]>
> Sent: Wednesday, May 12, 2021 1:20 PM
> To: Charlie Barto <Charles.Barto_at_[hidden]>; liaison_at_[hidden]; Zhihao Yuan <zy_at_[hidden]>
> Subject: Re: [wg14/wg21 liaison] P2174 Status (and a tenuous offer to help)
>
> On 12/05/2021 22.11, Charlie Barto wrote:
>> That's true, but for that distinction to be useful the behavior would have to differ depending on if the _outer_ struct is a temporary, right?
>
> I don't understand this comment.
>
> In C++, T{x,y} is an rvalue, so you can't take its address.
> If we make (T){x,y} the same as T[x,y}
> (which it practically is under some current compilers, I gather), your example is one which highlights the other difference of C vs. hypothetical-C++, beyond lifetime.
>
> This is independent of outer vs. inner struct.
>
> Jens
>
>
>> -----Original Message-----
>> From: Jens Maurer <Jens.Maurer_at_[hidden]>
>> Sent: Wednesday, May 12, 2021 1:06 PM
>> To: liaison_at_[hidden]; Zhihao Yuan <zy_at_[hidden]>
>> Cc: Charlie Barto <Charles.Barto_at_[hidden]>
>> Subject: Re: [wg14/wg21 liaison] P2174 Status (and a tenuous offer to
>> help)
>>
>> On 12/05/2021 21.51, Charlie Barto via Liaison wrote:
>>> But in any case the before/after comparison
>>>
>>> extern “C” VkResult vkCreateInstance(const VkInstanceCreateInfo*,
>>> const VKAllocationCallbacks*, VkInstance*);
>>>
>>> in c++:
>>>
>>> VkApplicationInfo appinfo {
>>> .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
>>> .pApplicationName = “Hello World”,
>>> .applicationVersion = VK_MAKE_VERSION(0, 1, 0),
>>> .pEngineName = “No Engine”,
>>> .apiVersion = VK_API_VERSION_1_2 };
>>> VkInstanceCreateInfo createInfo {
>>> .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
>>> .pApplicationInfo = &appinfo, }; VkInstance instance
>>> = 0; auto result = vkCreateInstance(&createInfo, nullptr, &instance);
>>>
>>> in C:
>>> VkInstance instance = 0;
>>> VkResult result = vkCreateInstance(&(VkInstanceCreateInfo){
>>> .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
>>> .pApplicationInfo = &(VkApplicationInfo) {
>>> .sType =
>>> VK_STRUCTURE_TYPE_APPLICATION_INFO,
>>> .pApplicationName = “Hello World”,
>>> .applicationVersion =
>>> VK_MAKE_VERSION(0, 1, 0),
>>> .pEngineName = “No Engine”,
>>> .apiVersion = VK_API_VERSION_1_2
>>> }}, NULL, &instance);
>>
>> I'd like to point out that this example is not about lifetime (full-expression vs. block), but about the fact that in C, compound literals are lvalues, so you can take their address.
>>
>> Jens
>>
>>
>

Received on 2021-05-12 16:05:18