c++20 : semantic change of volatile keyword

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
Post Reply
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

c++20 : semantic change of volatile keyword

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post 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
Raul
Posts: 43
Joined: Thu Aug 13, 2015 5:15 pm
Has thanked: 3 times
Been thanked: 1 time

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

Post 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
Post Reply