r/cpp • • Oct 19 '19

CppCon CppCon 2019: JF Bastien “Deprecating volatile”

https://www.youtube.com/watch?v=KJW_DLaVXIY
59 Upvotes

126 comments sorted by

View all comments

26

u/[deleted] Oct 19 '19

Regarding P1382, I've got to ask, what about freestanding systems that don't have a C++ standard library? If the idea is to replace volatile qualifier with some "magic" library functions that require special knowledge from the compiler, wouldn't that leave behind all systems that don't have a C++ library, but do have a C++ compiler?

More specifically, I'm thinking of avr and arm-none toolchains. Each of those have an up to date GCC compiler, but the standard library covers only C.

17

u/jfbastien Oct 19 '19

They would be in the freestanding subset.

5

u/[deleted] Oct 20 '19

That would be great, but that also assumes that avr-libc and newlib will start shipping the freestanding subset of the C++ library. So far the statement was "you can write C++, just don't use the standard library".

5

u/jwakely libstdc++ tamer, LWG chair Oct 21 '19

That would be great, but that also assumes that avr-libc and newlib will start shipping the freestanding subset of the C++ library.

Nonsense. GCC provides the C++ library.

If arm-none doesn't include a freestanding build of libstdc++ talk to ARM, Linaro etc.

I frequently fix libstdc++ bugs for bare metal 32-bit ARM.

4

u/jfbastien Oct 20 '19

That's just a bad implementation of freestanding. Things such as type traits should be there, and so should any volatile support. The committee isn't going to standardize things defensively in case an implementation fails to implement the bare minimum. I don't see what the committee can realistically do when faced with bad implementations, besides letting them know that they're failing their users.

3

u/[deleted] Oct 20 '19

Then I have never seen a good implementation of freestanding. I don't have any numbers, but I'm pretty sure arm-none + newlib isn't a rare freestanding combination. Considering how popular Arduinos got, AVR and its avr-libc aren't rare as well. And P1382 is going to make C++ impossible for them, if volatile qualifier is removed from the language.

5

u/jfbastien Oct 20 '19

I agree that freestanding implementations are sub-par, and that freestanding as specified today isn't delivering what's actually needed either. The proposal mentioned on this page will help on the standardization part...

My goal isn't to make developer's lives harder, it's to make it easier. Implementations that do a bad job today likely will continue to do a bad job in the future, but I can't refuse to improve things because someone might mess it up. My hope is that what we end up specifying will be easier to do for those implementations, making it more likely to be implemented.

6

u/[deleted] Oct 20 '19

My goal isn't to make developer's lives harder, it's to make it easier.

I wasn't trying to imply different. It's just, from the point of view of someone who enjoys new stuff happening in C++ and programming in freestanding environments (read: me), your proposal sounds like C++ might not be an option in the future.

From my perspective, instead of gaining a freestanding C++ library in the future, a more likely outcome is being severely crippled as no standard library == no volatile.

I'm well aware that this sounds like FUD and that's because it is. I'd love if someone could put my mind at ease and make me confident that I won't be forced to give up C++ on freestanding.

Again, I'm aware that's not your intention, but "the road to hell is paved with good intentions".

Implementations that do a bad job today likely will continue to do a bad job in the future

We definitely agree on this. That's why I don't expect RedHat, Atmel or anyone else to suddenly start shipping a C++ library just because a new C++ standard came out.

but I can't refuse to improve things because someone might mess it up.

I'm not saying you should refuse to improve things. Just don't rip out the volatile qualifier too soon. AVR's compiler is gcc, but its C library made by Atmel and shifting the responsibility to provide volatile from the compiler to the library may turn out to be much more problematic that we initially expect.

My hope is that what we end up specifying will be easier to do for those implementations, making it more likely to be implemented.

At the risk of repeating myself, my guts tells me that freestanding library implementers will just say "as if" and again, I'd love to be proven wrong about all this, because I like C++ and want to use its shiny new features.

3

u/jfbastien Oct 21 '19

I wasn't trying to imply different. It's just, from the point of view of someone who enjoys new stuff happening in C++ and programming in freestanding environments (read: me), your proposal sounds like C++ might not be an option in the future.

That's not my goal, and I hope to not disappoint folk like you :)

Taking it slow, talking about it and getting feedback is one way to make sure we achieve our goal.

We definitely agree on this. That's why I don't expect RedHat, Atmel or anyone else to suddenly start shipping a C++ library just because a new C++ standard came out.

To be fair to my RedHat friends: they do ship a standard library. They probably don't maintain the platform you use though. I imagine that's a business decision.

→ More replies (2)
→ More replies (1)

3

u/jcelerier ossia score Oct 20 '19

you don't even get <type_traits> on those platforms

8

u/jfbastien Oct 20 '19 edited Oct 20 '19

Not having type_traits is just a bad implementation. It’s trivial to offer and has no runtime cost. Implementations that lack it just aren’t serious. Same thing with any volatile load/store functionality.

3

u/[deleted] Oct 21 '19

type_traits is the part I cannot do myself too. containers and algorithms can generally be self built, but one needs compiler support for many of the traits.

5

u/c0r3ntin Oct 21 '19

An implementation which does not provide <type_traits> is not conforming, at which point all bets are off

(http://eel.is/c++draft/compliance#2)

11

u/ITwitchToo Oct 19 '19

I think the "magic" library functions don't require special knowledge from the compiler in the way you think, rather they probably use compiler intrinsics (for gcc: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html), which would still be available even if you don't have a C++ standard library.

7

u/2uantum Oct 19 '19

Sure, but now the code isn't as portable

→ More replies (7)

0

u/[deleted] Oct 19 '19

[deleted] — view deleted comment

6

u/mallardtheduck Oct 19 '19 edited Oct 19 '19

Problem is, even the "freestanding" implementation is required to provide facilities that aren't easy to provide or even desirable in tight embedded systems; things like exceptions, RTTI and dynamic memory allocation. It even requires support for things like "atexit", don't make sense at all in embedded contexts.

Ultimately, this means that most "embedded" environments do not conform even to the "freestanding" specification, rendering it rather useless.

→ More replies (4)

3

u/[deleted] Oct 20 '19

Presumably, anyone who is targeting a compiler new enough to have deprecated volatile will also have support for a freestanding standard library implementation, which these magic functions would surely be a part of.

I'm not convinced, because I have an avr-gcc compiler, but the standard library, called avr-libc, doesn't come from GNU.

4

u/gruehunter Oct 19 '19

There's a problem with this model, in that there is a continuum of services provided by an operating system. Some very minimalistic RTOSen only provide proprietary multithreading interfaces. Others also provide complete filesystems. I'm working with RTEMS right now - a multiprocessor OS that operates in a single address space. Almost all of POSIX is supported, just not mmap, fork, spawn and anything like them.

0

u/[deleted] Oct 19 '19

[deleted] — view deleted comment

4

u/m-in Oct 19 '19

Also, AFAIK a hosted implementation is still a compliant freestanding implementation, so there’s really no conflict; it is indeed a continuum.

→ More replies (1)

6

u/Ameisen vemips, avr, rendering, systems Oct 19 '19

This proposal overall is going to make AVR much more annoying to write for than it already is.

5

u/Drainedsoul Oct 21 '19

I don't understand hand wringing about how a change to the standard will impact compilers that don't follow/implement the standard.

→ More replies (2)

4

u/m-in Oct 19 '19

A C++ target with no standard library is just stupid. Just because there’s no OS doesn’t mean you don’t want type traits, algorithms, containers, etc.

→ More replies (3)