Page 1 of 1

c++20 : semantic change of volatile keyword

Posted: Sun May 10, 2020 12:45 pm
by alex31
Hello,

GCC 10.1 is out, and with it, come fairly complete c++20 support.

linux early adopter can try out arm-none-eabi-gcc-10.1 here : arm-none-eabi-gcc-10.1 archive

One think that will hit embedded developper is the change relative to the volatile keyword:
https://www.youtube.com/watch?v=KJW_DLaVXIY

in short,
1/volatile can only be used to declare variable, and no be in signature function
2/compound assignment (+=, |= ,&=, ....) is forbidden on volatile variable.

So, no hurry, gcc10 will not hit arm official repository before a while, but when it will do, lot of code will break in stm and chibios header that will be include by c++20 code.

Don't kwow if this change will be include in future revision of C language, but that's not impossible.

Alexandre

Re: c++20 : semantic change of volatile keyword

Posted: Mon May 11, 2020 10:22 am
by Giovanni
That would be a mess, most likely. The kernels do not use volatile much but register header files are filled with those.

Giovanni

Re: c++20 : semantic change of volatile keyword

Posted: Mon May 11, 2020 5:13 pm
by Raul
I think the intent is to clear the muddy usages of volatile, frequently confused with atomicity in multithreaded development under C++.

The qualifier will remain present for load and store operations, in here Jf Bastien's mentions having a more expressive alternative perhaps something like volatile_load, volatile_store as instructions instead of the meaning of volatile as a property of the type.

Alex, from what I could gather volatile will still be accepted as a member qualifier (Goal 3 in the video) for C++20 although longer term is for it to be gone. On the contrary, non-reference & non-pointer return and parameters variable volatile qualifications are deprecated.

Thanks for sharing this,

Raul