C++20 Modules with GCC11
scrubs 2021-08-19 04:46:42 +0000 UTC [ - ]
* It'll be decades before our existing c++ code base is converted to modules meaning same cmake, dpkg, and all manner of nonsense ...
* clibs used by c++ are not impacted
* Modules are unlikely to help for os headers
I'm trying to move to go when I can and pure rust otherwise. After many years of c++ build hell on top of legion internal c++ code .. building has become a cosmic pain in the butt.
jcelerier 2021-08-19 07:19:50 +0000 UTC [ - ]
> I'm trying to move to go when I can and pure rust otherwise.
I don't understand in which universe replacing includes by imports takes more time than a full rewrite in a different language
speters 2021-08-19 09:08:00 +0000 UTC [ - ]
pjmlp 2021-08-19 06:29:33 +0000 UTC [ - ]
mtzet 2021-08-19 06:53:12 +0000 UTC [ - ]
fsloth 2021-08-19 07:05:56 +0000 UTC [ - ]
pjmlp 2021-08-19 10:02:55 +0000 UTC [ - ]
ziotom78 2021-08-19 07:06:31 +0000 UTC [ - ]
tialaramex 2021-08-19 11:57:55 +0000 UTC [ - ]
jcelerier 2021-08-19 12:12:50 +0000 UTC [ - ]
is it though. I have plenty of .h in my /usr/include with copyrights between 1980 and 1985. Sure, it's not modern best practices, but at least it's possible... and for a one-off task there's definitely not much point in doing a wrapper.
tialaramex 2021-08-19 16:47:34 +0000 UTC [ - ]
Maybe it gives you a raw pointer to new resources. In 2021 those are just loose references which don't signify ownership, you need the wrapper to avoid this confusion leaking into your program.
Maybe it gives you an integer handle which needs to be passed to some other API call to "release" the handle when you're done with it. Again you'll want a wrapper to handle this properly in your code or you may leak resources. You'll also want a wrapper because one integer is the same as another, but you probably shouldn't finished_with_cow(dog_number) or clean_up_dog(cow_number) even though those compile.
Being forty years old it invariably won't be thread safe, so you'd also want to wrap it for that reason unless (as is often the case in C++) your code isn't thread safe anyway.
"at least it's possible" isn't a differentiator. As I said you could also access this 40 year old API from Rust, but you'd want to build a wrapper for it because it the behaviour is so violently different from what's expected in the modern ecosystem.
pjmlp 2021-08-19 12:30:05 +0000 UTC [ - ]
Naturally you are being pedantic by focusing on exactly 40 years.
tialaramex 2021-08-19 17:02:45 +0000 UTC [ - ]
This reminds me of BeOS which claimed to be a C++ operating system and had abstract classes like "BStatable" representing things that can be "stat'd" and which comes with a bunch of methods that use out-pointers for integers that can in turn be bit-compared to constants like S_IWUSR. Very C++. Much object orientation. Wow.
[ Behind the scenes of course it's the stat() system call you remember from Unix and C. ]
It's true that there are really significant libraries people care about for C++ and some of those libraries existed five, ten, in a few cases even twenty-five years ago, but the older they are the uglier they get and more likely they are to drive people away from C++ rather than toward it. If your argument becomes something like "Why use Rust when C++ has COM?" you might as well reveal your membership of the Rust Evangelism Strike Force.
gmueckl 2021-08-19 06:55:43 +0000 UTC [ - ]
When playing with modules, I noticed a major caveat that makes me dislike them very much: the standard says that modules must form acyclic graphs. This means you still cannot get rid of forward declarations and you must put interfaces and implementations into different files for any realistically sized code base. So, in terms of effort, you still have to maintain the equivalemt of headers, just with a different name and less preprocessor macro interference.
hoseja 2021-08-19 07:12:37 +0000 UTC [ - ]
gmueckl 2021-08-19 08:12:17 +0000 UTC [ - ]
creata 2021-08-19 08:32:13 +0000 UTC [ - ]
Rust allows cyclic dependencies between modules within a single crate, but not between crates.
pjmlp 2021-08-19 10:12:12 +0000 UTC [ - ]
gmueckl 2021-08-19 10:22:04 +0000 UTC [ - ]
pjmlp 2021-08-19 10:26:53 +0000 UTC [ - ]
Probably there are others as well.
gmueckl 2021-08-19 10:32:12 +0000 UTC [ - ]
pjmlp 2021-08-19 11:38:57 +0000 UTC [ - ]
If you want to stay in one language, then F# imposes compilation order, even Visual Studio has support to rearrange file order on the project file.
dathinab 2021-08-19 00:26:33 +0000 UTC [ - ]
But wow is that a multiple degrees more complex then in most other languages.
otabdeveloper4 2021-08-19 08:59:00 +0000 UTC [ - ]
You're not gonna use Rust or Zig to write code for some obscure DSP CPU with a ridiculous architecture and no OS.
tialaramex 2021-08-19 12:16:12 +0000 UTC [ - ]
Of course with no OS you can't run Rust's standard library as this expects OS services to underpin it. But you can have core features, and if you've got "no OS" you presumably were expecting to write anything you needed anyway.
The reality for modern C++ is that you're on a Microsoft platform, or you're on GCC, or you're on Clang, there is no fourth vendor - you are screwed and nothing works. The era of $$$ proprietary compilers for weird targets on C++ ended and isn't coming back, C++ got too complicated for them and they gradually stopped implementing new features. But if you're on Clang you already have LLVM, which is a long way toward having Rust. If you're on a Microsoft platform that is the OS, I know, seems like they could do more but they didn't.
When you say "ridiculous architecture" if you got too far off piste you can't have modern C++ either. Even as you stray into the black zone stuff gets very fragile and I wouldn't risk it. Your CPU integer arithmetic isn't technically required to be two's complement for example, but good luck fixing all the weird things that break if it isn't.
jokoon 2021-08-19 11:14:55 +0000 UTC [ - ]
Although, this is for people who make modules, not for module users.
As long as modules are written and compiled, they're both faster and easier to use and re-use than headers+libraries, although I'm curious to see if this covers both multithreaded libs and not, debug/release symbols, 32 or 64 bits and so on. So far all those options means there are 8 versions for each lib.
I've heard that now, libraries built with a version of MSVC are compatible with future version of MSVC, which means I don't need to build libraries each time I use a new version of MSVC.
tdiff 2021-08-19 08:43:06 +0000 UTC [ - ]
pjmlp 2021-08-19 10:14:10 +0000 UTC [ - ]
https://devblogs.microsoft.com/cppblog/moving-a-project-to-c...
glouwbug 2021-08-19 00:13:03 +0000 UTC [ - ]
bmurphy1976 2021-08-19 02:42:59 +0000 UTC [ - ]
lelanthran 2021-08-19 09:02:34 +0000 UTC [ - ]
It's hard to get something better than header files; modules don't provide the same functionality, as far as I can see.
I think headers will remain purely for practical purposes.
pjmlp 2021-08-19 10:16:25 +0000 UTC [ - ]
Check Modula-2 documentation, or Turbo Pascal for MS-DOS or Apple's Object Pascal.
lelanthran 2021-08-19 11:47:08 +0000 UTC [ - ]
Header files serve as a library interface for almost all languages out there, and are so simple that for the most part they can automatically be used from other languages to access the library.
C++ Modules, as far as I can tell anyway, are for C++ programs to use only, to access C++-only libraries.
pjmlp 2021-08-19 12:28:22 +0000 UTC [ - ]
lelanthran 2021-08-19 12:29:54 +0000 UTC [ - ]
I dunno, I never claimed that.
pjmlp 2021-08-19 12:51:38 +0000 UTC [ - ]
lelanthran 2021-08-19 13:28:04 +0000 UTC [ - ]
What does that have to do with compilation? I use C headers all the time from Java projects and I've never had to compile them. Not manually anyway.
Headers are usable from Python, Tcl, Lua, Java, C# and a whole lot of other languages that similarly don't require compilation and don't require much effort further than issuing a single command.
The modules being proposed as a replacement for headers cannot, and will never, provide this functionality.
mhh__ 2021-08-19 00:53:53 +0000 UTC [ - ]
phibz 2021-08-19 00:57:59 +0000 UTC [ - ]
copperx 2021-08-19 04:40:23 +0000 UTC [ - ]
qweqwweqwe-90i 2021-08-19 00:47:05 +0000 UTC [ - ]
steveklabnik 2021-08-19 00:49:35 +0000 UTC [ - ]
But modules themselves are standardized, and so you should expect that after some time, you'll have stuff that works on all implementations. I don't believe that any of them are complete yet, which is why you see these differences currently.
(Caveats: I have followed the development of modules semi closely but am by no means an expert.)
not2b 2021-08-19 01:07:21 +0000 UTC [ - ]
But modules are very new and I doubt if enough corner cases are nailed down yet.
gumby 2021-08-19 01:52:51 +0000 UTC [ - ]
For generated code, definitely. But for example their standard libraries are different so you still can't, say, compile something in gcc that uses std::string and expect to be able to link it to something compiled with clang that uses std::string unless you are careful to use the headers (and .a files) of the same libc++ or libstdc++
I consider this a feature, not a bug -- diversity in implementation is a plus.
summerlight 2021-08-19 01:13:09 +0000 UTC [ - ]
bigcheesegs 2021-08-19 03:21:16 +0000 UTC [ - ]
baybal2 2021-08-19 01:01:30 +0000 UTC [ - ]
There is no real chance to see it becoming a part of the C standard, because C is just that compact, and simple.
Yet, pkgconf will be a perfect base for pan-C package metadata standard outside of the standard.
bregma 2021-08-19 11:14:46 +0000 UTC [ - ]
baybal2 2021-08-19 15:14:08 +0000 UTC [ - ]
But as a part of a wider C world, it's probably the most portable semblance of standardised package metadata system.
jcelerier 2021-08-19 07:24:13 +0000 UTC [ - ]
lelanthran 2021-08-19 09:05:01 +0000 UTC [ - ]
Yes, but to be fair most things suck on Windows because that userbase only recently decided that portability is a good thing.
As we move forward and Microsoft products stop being the odd one out, the suckage will get lower.
pjmlp 2021-08-19 10:19:10 +0000 UTC [ - ]
lelanthran 2021-08-19 11:48:53 +0000 UTC [ - ]
pjmlp 2021-08-19 12:25:09 +0000 UTC [ - ]
lelanthran 2021-08-19 12:29:24 +0000 UTC [ - ]
pjmlp 2021-08-19 10:17:48 +0000 UTC [ - ]
I guess someone is still using K&R C book as reference instead of ISO C18.
jstimpfle 2021-08-19 11:23:45 +0000 UTC [ - ]
pjmlp 2021-08-19 11:38:04 +0000 UTC [ - ]
tialaramex 2021-08-19 14:03:37 +0000 UTC [ - ]
I have a copy of the 2nd edition "The C Programming Language" by K&R from 1988 which discusses what is in effect the standard C89 language. Appendix C calls out the substantive changes compared to their earlier book, it is three pages long.
It's true that these changes are significant, C would be a very different language without enum for example, or with "old-style" (already deprecated by the time the book was written in 1988) function declarations. But the language is still very compact.
The book explains and describes essentially the entire language, and outlines the standard library, in under 300 pages. Only a few years later, the 2nd edition of Stroustrup's book "The C++ Programming Language" is more than twice the length, and introduces numerous already anachronistic features in notional support of C, which had meanwhile deprecated them. This takes up about 700 pages.
Stroustrup not only grandfathers in features C had by then cast off (such as weird function definitions) but also introduces crazy nonsense that I hope nobody ever used in the name of "backward compatibility" e.g. hey why not overload both of the increment operators (themselves bad ideas C++ inherited from C) with the same function? Imagine trying to pretend to yourself that you believe this is a reasonable thing to do, while also pretending to believe operator overloading delivers "unsurprising" semantics.
pjmlp 2021-08-19 15:18:27 +0000 UTC [ - ]
Also you should be comparing ISO standard documents editions, not books.
tialaramex 2021-08-19 16:33:11 +0000 UTC [ - ]
In contrast Stroustrup's work is much bigger, and yet things that would later be claimed to be very important don't warrant a mention. Even assuming we accept that Bjarne is simply retrospectively imagining a motivation he never had at the time, and so these were indeed tiny inconsequential features when the book was written, somehow the "survey" of the C++ language in the much longer book is inadequate while K&R cover their entire language very well in fewer pages. Simply this is because in fact C is a "compact and simple" language.
People make a lot of claims about C that I disagree with, but it certainly is simple. If I could make modest adjustments in the light of what we know now, to what was standardised in ANSI C in 1989 - a few of them would perhaps simplify it further (don't do implicit narrowing just emit a diagnostic and give up; don't try to make volatile a type qualifier) but many would make it more complicated instead (more type safety, sum-types, and of course an actual length+pointer string type) just arguably to our considerable benefit.
jstimpfle 2021-08-19 11:51:32 +0000 UTC [ - ]
Everybody thinks they know shit and yet they don't know all the details even after 5 years of practice (and let's not even look at C++!). Welcome to reality.
However, a programmer's goal is not to know all the (often irrelevant) details. And it's not to win a pub quiz.
The goal is to know enough to be able to communicate ideas in a clear and straightforward way, and to be productive.
pjmlp 2021-08-19 12:27:40 +0000 UTC [ - ]
Than lets limit the questions to what is UB, which is needed for daily programming activities, specially when one cares about security assessments, I am betting on the same outcome.
jstimpfle 2021-08-19 12:57:36 +0000 UTC [ - ]
The rules around UB can be annoying, but I don't think this is a recent development, either. Probably compiler optimizations are to blame for some of this. For actual practice and pedestrian code, obscure UB bugs have little relevance.
Food for thought: C compilers are free to insert runtime checks to abort when UB occurs.
vlovich123 2021-08-19 14:11:41 +0000 UTC [ - ]
I understand the basic concept of UB but some of the rules can have nuance and be easy to run afoul of. If you’re not running UBSAN on non-trivial codebases (lots of LOC and/or multiple devs), you are likely to have UB. Same goes for ASAN and TSAN issues. I always have humility around this topic as I’m not a compiler author. Heck, the compiler authors I’ve worked with themselves know the knives are sharp and work with humility.
jstimpfle 2021-08-19 15:02:02 +0000 UTC [ - ]
My conclusion is that C lets me do what I want straightforwardly, I still haven't found this quality in a different language (there is inertia, I've only tried Zig for an hour for example and gave up in frustration). Also, to some degree I understand where most UB definitions are coming from and even agree with some of them.
The basic idea behind UB is to give the compiler a free pass (optimization, and not having to detect corruption) if the program has a bug anyway.
In some cases there can be legitimate surprises, when the programmer made some assumptions about guarantees that C can't give and that a newer language (without the historical baggage of supporting some architecture) can give, which might result in the compiler transforming a little bug into something bigger (more dangerous?). An example that I've personally learned at some point is integer shifting and masking in conjunction with implicit type promotion to int (which is signed).
All in all though, while I'm not be the most sophisticated programmer and most of my programms are never exposed to hacking attempts, just anecdotally I've had very, very little headaches from UB.
pjmlp 2021-08-19 15:15:43 +0000 UTC [ - ]
If you don't like it to be pointed out C's weaknesses, don't engage.
I can play language lawyer quite well, including security standards.
Yes compilers are free to do many things to fix C, except that many don't.
jstimpfle 2021-08-19 15:52:35 +0000 UTC [ - ]
But this is the point. The language is quite compact and simple and if you think like a computer, it just "makes sense". Counting pages of the standards is not an accurate measure of language complexity.
Certain subtleties are not even forced by the language, rather they arise from natural requirements (such as performance, implementation simplicity, modularity, compatibility, etc).
By and large, it's not the language, but rather what people do with it. The language gets out of the way.
dleslie 2021-08-19 00:23:20 +0000 UTC [ - ]
I wonder how many folks, like me, have stopped using C++ because it's too much effort to manage the build system and the overhead of headers adds too much to compile time?
An enormous draw for alternatives, like Rust, Zig, Nim et al is that they simply don't have these problems.
tempest_ 2021-08-19 01:25:34 +0000 UTC [ - ]
No messing with autoconfs, and make files that spit out some random gcc error I have to debug.
To be fair however I am also not too interested in c++ and its 30 years of foot guns either so take it for what its worth.
saagarjha 2021-08-19 03:32:42 +0000 UTC [ - ]
pjmlp 2021-08-19 06:32:08 +0000 UTC [ - ]
Google and Microsoft aren't using cargo on their projects, rather had to come up with their own build tool.
zeusk 2021-08-19 07:30:47 +0000 UTC [ - ]
ithkuil 2021-08-19 07:20:39 +0000 UTC [ - ]
jcelerier 2021-08-19 09:34:53 +0000 UTC [ - ]
mtzet 2021-08-19 11:24:29 +0000 UTC [ - ]
ridiculous_fish 2021-08-19 03:46:30 +0000 UTC [ - ]
https://doc.rust-lang.org/src/std/sys/unix/os.rs.html#38
steveklabnik 2021-08-19 04:20:32 +0000 UTC [ - ]
nicoburns 2021-08-19 09:54:01 +0000 UTC [ - ]
saghm 2021-08-19 04:10:23 +0000 UTC [ - ]
pjmlp 2021-08-19 06:27:20 +0000 UTC [ - ]
ridiculous_fish 2021-08-19 03:29:37 +0000 UTC [ - ]
comex 2021-08-19 03:43:27 +0000 UTC [ - ]
skywal_l 2021-08-19 05:35:03 +0000 UTC [ - ]
But there is an effort[0] from the "core team" (meaning Andrew Kelley the author or Zig) to push for an "official solution".
Maybe, the same way Zig makes cross-compiling C/C++ easier we might see a Zig package manager making C/C++ packaging easier too.
[0] https://github.com/ziglang/zig/issues/943
AndyKelley 2021-08-19 05:45:40 +0000 UTC [ - ]
> Having a package manager built into the Zig compiler is a long-anticipated feature. Zig 0.8.0 does not have this feature.
> If the package manager works well, people will use it, which means building Zig projects will involve compiling more lines of Zig code, which means the Zig compiler must get faster, better at incremental compilation, and better at resource management.
> Therefore, the package manager depends on finishing the Self-Hosted Compiler, since it is planned to have these improved performance characteristics, while the Bootstrap Compiler is not planned to have them.
I can't help but mention, I am incredibly excited about how well the self-hosted compiler is coming along. Progress is swift, and all the ambitious design decisions (fully incremental compilation[1], extremely fast debug builds[2], low memory usage, multi-threaded) are intact. I anticipate it to make quite a splash once it becomes generally usable.
I don't expect the package manager to take nearly as long to develop.
[0]: https://ziglang.org/download/0.8.0/release-notes.html#Packag...
[1]: https://vimeo.com/491488902
[2]: https://twitter.com/andy_kelley/status/1416485475125141504
makapuf 2021-08-19 07:59:06 +0000 UTC [ - ]
dureuill 2021-08-19 08:53:49 +0000 UTC [ - ]
pjmlp 2021-08-19 06:26:35 +0000 UTC [ - ]
It is just many anti-IDE folks never get to adopt them.
gmueckl 2021-08-19 12:15:07 +0000 UTC [ - ]
pjmlp 2021-08-19 12:30:49 +0000 UTC [ - ]
gmueckl 2021-08-19 16:00:52 +0000 UTC [ - ]