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 22:20:04 +0200
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_gmx.net>
> Sent: Wednesday, May 12, 2021 1:06 PM
> To: liaison_at_[hidden]; Zhihao Yuan <zy_at_[hidden]t>
> 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 15:20:15