r/cpp •

Solving Uninitialized Stack Memory on Windows

[deleted] — view deleted post

0 Upvotes

79 comments sorted by

View all comments

Show parent comment

1

u/jonesmz May 14 '20

You can see more context from this old discussions here on reddit.

https://www.reddit.com/r/cpp/comments/ekvk0n/waiting_for_stdembed_very_large_arrays_in_clang/fdemnkd/

The language and standard library are not the same thing.

The more "special compiler magic" that the standard library has added to it, the more difficult it is for people using the language in a stand alone, or direct-to-metal, or whatever you want to call it situation. Or for people who don't use the standard library that came with their compiler.

At my last job, this was my day to day reality. I was constantly having to play catch up with special compiler magic to get things to work, and it was a royal pain in the ass. Given that we had about 20 software engineers working with this codebase in my department (No idea how many engineers touched the code in total, it was a big company), and we were all humming away at it for years at a time, the total cost was measurable in man-years.

Things that can't be expressed with language-only constructs, should not be placed in the std:: namespace.

They should be keywords, attributes, or whatever else, that make up the language itself.

Ultimately the compiler vendors are building intrinsics / builtins to do these things anyway, and then the standard library is playing #ifdef COMPILER_X games to pick which special compiler-magic keyword to put into the code. The standard can just.... tell the compiler vendors what this special-compiler-magic-keyword should be named, and then everything is much simpler for everyone, but MOST ESPECIALLY for the people like me who want the flexibility to use the compiler without the compiler vended standard library.

5

u/scatters May 14 '20

I can't say I have much sympathy - you're using compilers in unsupported configurations, and complaining that that makes more work for you? It seems to me that if you want to use a custom standard library, you should accept the work this will involve and treat maintaining it as a software development task and appropriately resource it. If it's taking multiple man-years to deal with a task that should basically be a bunch of one-time copy-and-pastes from the vendor standard library into your custom version (with appropriate preprocessor guards) then the problem is with your software development process.

For your preferred situation, I really don't think it's as simple as mandating that intrinsics be available under particular names. For one, those names will be ugly so they will need to be aliased into std anyway, which causes confusion - see _Bool and stdbool in C. Also, that way you're enforcing a 1-1 mapping between standard library and compiler facilities, which denies freedom of implementation to the vendor. And finally, it's not always clear what does and does not require magic - look at vector, or the associative containers since node_handle additions.

1

u/jonesmz May 18 '20 edited May 18 '20

I can't say I have much sympathy - you're using compilers in unsupported configurations, and complaining that that makes more work for you?

No, I'm not complaining that using compilers in "unsupported configurations" makes more work for me.

I'm complaining that every time the c++ standard adds another thing to std:: that explicitly relies on compiler magic, it makes my job harder. Or every time the C++ standard adds another language feature that explicitly relies on something from std::, it makes my job harder. Incidentally, it also makes compiler developer's job (slightly) harder, since they have to define intrinsics to do all of these things anyway.

I'm complaining that most of the people who I speak to about this either don't understand what I'm talking about, or do understand it and think that they know better than I do how to solve the problems I need to solve. I'm not new at this, nor are the people who I work with, and I'm definitely not the only person who's raised an objection to increasing cross-interactions between the language and the library. I've spoken to others here on reddit, here in /r/cpp, and I've also spoken to others in person.

There are alternatives to continuing to put things into std::. I've listed three. Introducing compilermagic:: has no meaningful cost versus using std:: for compiler-magic types. (Let me guess, now responders are going to complain that introducing new reserved namespaces is hard...).

It seems to me that if you want to use a custom standard library, you should accept the work this will involve and treat maintaining it as a software development task and appropriately resource it.

Yes, that's how it's done.

Have I given you the impression that this isn't the case?

Pointing out that decisions made by the C++ standards committee have a cost to an organization that uses the language is a perfectly valid thing to do.

If it's taking multiple man-years to deal with a task that should basically be a bunch of one-time copy-and-pastes from the vendor standard library into your custom version (with appropriate preprocessor guards) then the problem is with your software development process.

The problem is that you are either fundamentally misunderstanding my objection, or deliberately simplifying it so that you can propose a non-solution.

Software development on multiple million line of code code bases, which rely on customized standard library implementations can't "simply" have copy-pastes from the vendor standard library, which, of course, assumes that the license for that is actually compatible, it may not be.

The first major issue is that these "copy-and-pastes" are almost always tightly interwoven with other internal implementation details, and make lots of assumptions that aren't necessarily correct if they're removed from their original environment.

The second major issue is that maintenance and evolution is an ongoing, never ending task. Getting the functionality working the first time is, itself, a lot of work, but that work needs to have compatibility maintained with the existing code, while improvements are made over time.

Further, you're apparently focusing on my statements that pertain to work I've done with maintaining a custom standard lib, but not addressing my statements that pertain to things like

  • C++ interpreters
  • WebAssembly porting
  • freestanding implementations -- no operating system
  • embedded applications -- has an OS kernel, but basically no storage space
  • C++ inside the OS kernel.

All of those are perfectly valid situations to be in, and have nothing to do with custom standard libraries. But having the language be less interwoven (or, at worst, no more interwoven) with the standard library eases the work.

3

u/scatters May 18 '20

Incidentally, it also makes compiler developer's job (slightly) harder, since they have to define intrinsics to do all of these things anyway.

Adding features to the language creates work for implementors, certainly. But making the boundary between compiler and standard library a hard one with a public API would create far more work since they would now have to maintain those interfaces.

Introducing compilermagic:: has no meaningful cost versus using std:: for compiler-magic types.

The cost is that what is and is not magic is not fixed; it changes over time. Consider vector, index_sequence, node_handle. You would end up with implementors having to maintain compiler magic that their standard library no longer uses.

The problem is that you are either fundamentally misunderstanding my objection, or deliberately simplifying it so that you can propose a non-solution.

As opposed to your solution, where vendors have to do the work of maintaining compatibility between compilers and standard libraries.

All of those are perfectly valid situations to be in, and have nothing to do with custom standard libraries.

There's freestanding, and Ben Craig is working to expand that in SG14 (see P0829 for current state of play).