C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Use of volatile as function argument should not be deprecated.

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 09 Jun 2022 10:55:08 +0100
Hi,

I think your use case has merit, but I think volatile is the wrong tool here. The use case would be better served by an attribute. I'm not aware of an attribute that has this effect though.

Cheers,
Lénárd


On 8 June 2022 22:46:58 BST, "Ryan P. Nicholl via Std-Proposals" <std-proposals_at_[hidden]> wrote:
>Hello. I just wanted to point out a usage of volatile that I don't think should be deprecated. Namely, the use of volatile on a function argument.
>
>This may sound weird but it can be useful to create a parameter like 'volatile bool collect_debug_info = false' that gets passed down to functions that get called by the function. The function is called with it always false so if the function is inlined the compiler will elide all the instances of it being checked. Simply editing the variable in the debugger can be useful to collect information this way for a specific execution without having to do anything more complicated. I would therefore suggest this be either 1. un-deprecated, possibly as a defect report for C++20 or 2. a new keyword or attribute specifically for values that are intended to be changed in a debugger so that it still warns people misusing it for threading. I'm also unsure about the value of deprecating += and such, but it's definitely understandable.
>
>--
>Ryan P. Nicholl
>Tel: (678)-358-7765

Received on 2022-06-09 09:55:14