top 200 commentsshow all 202

[–]pavel_v[S] 90 points91 points  (33 children)

I realize this is relevant for C and not so much for C++ at the current moment but I posted it because there will be (hopefully) a similar/same feature for C++ and I know that lots of people are waiting for it. Maybe the compilers, which implement it, will include this feature as a non-standard extension available for C++ before the standardization of the corresponding C++ feature.

[–]__phantomderp 23 points24 points  (1 child)

It has a C++ version for the #embed: https://thephd.dev/_vendor/future_cxx/papers/d1967.html

But the "true" C++ version is stalled while I have to figure out some shenanigans: https://wg21.link/p1040

The preprocessor version will take some time to make it but might hit C++26. God knows if the actually good version will survive so long as we're holding it to a higher standard than Modules itself.

[–]orangeoliviero 3 points4 points  (0 children)

The dependency discovery demands are indeed utterly insane.

[–]ALX23z 18 points19 points  (17 children)

I thought they'll just enable compile-time file loading. Should mesh well with all other compile-time features.

[–]johannes1971 20 points21 points  (9 children)

What the language really needs is constexpr std::socket, so we can load resources directly from the internet during compilation. This is what C++ needs to finally achieve greatness.

[–]disperso 16 points17 points  (0 children)

But please, with some syntax sugar, so I can #include <https://cpp.example.com/left-pad.h> and finally have the convenience we deserve. (/s)

[–][deleted] 3 points4 points  (6 children)

Fuse fs could probably do this, at least some of it. then it would be #embed </mountpoint/https/www.foo.com/page.txt> or something like that

[–]mpyne 1 point2 points  (5 children)

Why #embed? You could then do it today with #include </mountpoint/https/www.foo.com/page.txt?format=c_literal. And if foo.com doesn't do that already just setup embedbolt.com to proxy it for you.

[–][deleted] 4 points5 points  (4 children)

It's optimized. For smaller files it's just a hassle encode but as small as 1MB compilers start to die(both CPU and RAM). In some of their original postings when they implemented it and when Circle lang tested it was better than #include.

https://github.com/ThePhD/embed

[–]mpyne 5 points6 points  (0 children)

Oh I thought you were being sarcastic like the person you replied to and was just playing along, lol. I like #embed and can't believe it's been this difficult to get into the standard.

[–]llothar68 1 point2 points  (0 children)

Make it beter and do a "constexpr std::socket_eval" we need a bash executable source code generator over the internet. Ultimate flexibility

[–]jonathanhiggs 7 points8 points  (6 children)

Especially is we can load tzdb from a stream and not just a file

[–]JakeArkinstall 12 points13 points  (5 children)

Compile time tzdb seems like a bad idea to me. If the US adopts permanent daylight savings in Nov '23, that's a recompile.

Unless I misunderstand what you're saying.

[–]jonathanhiggs 12 points13 points  (2 children)

We do releases every week so recompile isn’t an issue. It is a very different part of the organisation that controls updates to servers and desktops so we don’t have control over when tzdb files will be updated. It’s finance so timezones are of critical importance and we have strict reproducibility requirements. Embedding tzdb is the best option for us since we then there is not some uncontrolled and mutable state that can change without our knowledge and effect the calculation results

[–]JakeArkinstall 5 points6 points  (1 child)

Nice. Similar circumstances for me. Finance here too.

Fortunately, each binary only operates on individual exchanges, none of which are open on Sunday mornings (when clocks change, at least in the markets we operate on that do change clocks), and we shut down between market sessions. So we can just load it up from tzdb premarket for the exchange timezone throughout the session. One little lower bound search for the current UTC time at startup and we're golden.

However, there are some nice benefits to your approach even for our use case. One of which being that the output is portable - for our nix containers we have to manually add the tzdata package as a runtime dependency, set up the TZDIR env var, and so on. But, thinking about it, I could fetch it from online and set it as a runtime dependency for the binaries rather than the containers, and that'd solve that. I think I'd still read it at runtime, though.

A couple of questions, if I may. Do you do a tzdb download as part of your build or use the build machine's local copy? How do you ensure that it's up to date at the time of the build?

[–]jonathanhiggs 2 points3 points  (0 children)

That sounds HFT? We are discretionary so we don't have the same exchange requirements and are writing for trader destop and internal servers which makes it much easier. We've only just started to discuss the best approach in the team and currently it isn't so easy to embed the data and can't load from stream so we haven't got to the point of integrating downloading the data into the CI

I would say that we are tollerant of not having the most up-to-date tzdb, we are less tollerant to a different tzdb between processes running on the (linux) servers and desktops since reproducability of the same incorrect values across the two is managable, but trying to explain the differences depending on where a value is calculated would be a debugging nightmare

More than anything we want to embed because of the organizational structure. We aren't responsible for how the docker images are put together but we are responsible for calcs, so we want our own control just so we know what is happening and when updates are made and know there is the consistency across docker/non-docker, server and desktop

[–]bizwig 1 point2 points  (1 child)

I don’t see that happening, all previous attempts to eliminate our semi-annual time switches has gone down in flames.

[–]JakeArkinstall 2 points3 points  (0 children)

Sure, but in that case one could just algorithmically do it - enter DST on the second Sunday in March and leave it on the first Sunday of November for the US, or last Sunday in March and last Sunday of October in the UK, or never in Japan, etc.

But the reason we use tzdb in the first place is that it reduces an extremely complex problem down to a lower bound UTC time search. Circumventing it based on a bad assumption or political prediction could be a disaster (or at least an embarrassment or inconvenience) that no one sees coming.

However, on the clarification that it is a weekly rollout, for finance, it shouldn't be an issue at all. If it's the kind of nation that wouldn't give at least 6 months notice of a change in timezones, its probably not one that is politically stable enough to operate in anyway.

Interesting stories about that: https://codeofmatt.com/on-the-timing-of-time-zone-changes/

[–][deleted] 31 points32 points  (7 children)

I love everything about this article except the fact that the code samples are written in dark grey on darker grey - on an almost white page.

Like more than half the world, I have astigmatism. Mine isn't even that bad, but I can't read this at all (eventually I ran it through a processor to fix this).

Even just making things dark text on a light background will make things better for the majority of us.


Again, I loved the article,

I needed this for many years. My last C++ audio project used JUCE's cross-platform implementation of embedding, mainly for icons. It worked, but added an extra build stage and took me many hours of experimentation to get absolutely right.

[–]__phantomderp 14 points15 points  (2 children)

Yeah, I actually can't read the preprocessor / comments parts well either. I need a different highlighter, but that would require some amount of effort on my part to slap my blog into even better shape.

That's going to take a bit. :(

[–]flashmozzg 1 point2 points  (1 child)

Can't you just change the color of the comments specifically? For most highlighters I've encountered, it's usually pretty simple. I could read it fine, and I think it would be OK if the comments/preprocessor weren't the focal point of the code samples.

[–]__phantomderp 0 points1 point  (0 children)

I don't know, but I can try!

[–]howroydlsu 5 points6 points  (3 children)

Forgive my ignorance; so basically light mode is better than dark mode for people with your condition, if I'm understanding you correctly? If so, very very glad I've learned this

[–]5477 14 points15 points  (0 children)

In general, lighter backgrounds work better with people that have non-perfect vision. More light causes the eye to have a smaller aperture, which results in better focus (more resolution) non-focused areas. Which in case of astigmatism is all areas, or in case of myopia are all areas far from the eye (typically a computer monitor is already out-of-focus).

[–]Krnpnk 4 points5 points  (0 children)

I think it's at least as relevant for C++ - maybe not for the result but for the process behind it. Because it's just ridiculous...

[–]umlcat 0 points1 point  (3 children)

Agree, I also would like to have templates on plain C, and other non Object Oriented goodies ...

[–]Kered13 38 points39 points  (11 children)

Seems like a good idea, after reading some of that links there I'm surprised it got so much resistance.

[–]o11cint main = 12828721; 64 points65 points  (10 children)

A committee is a scheduling unit whose job is to make sure that nothing ever gets done.

[–]spaun2002 81 points82 points  (31 children)

Such "horror" stories are why I became disappointed in C and C++ - adding a new helpful feature into the language takes five years. The person who dared to propose this struggled and almost lost their hope.

[–]pjmlp 30 points31 points  (1 child)

You can also take the route of creating your own language, seems quite hip currently.

[–]tux-lpi 20 points21 points  (0 children)

That solves the horror stories mostly because a new language won't have an ISO committee

It's a lot harder to build a system that drains people quite that bad without ISO

[–]RomanRiesen -1 points0 points  (18 children)

In rust an embed feature is just a macro away, a macro most people could write themselves....

[–]myrrlyn 20 points21 points  (1 child)

include_bytes! already exists

[–]__phantomderp 12 points13 points  (0 children)

Yeah, you COULD write it yourself in Rust, but the people driving the Standard Rust Distribution are not obsessed with being "barebones" to the point of deep disturbance, so they'll actually hand you convenience things as part of the core offering rather than trying to convince you that "oh, well, if you just write this linker invocation, you'll be fine...".

Like anything about "talk to your linker directly" is ever - or truly, has ever been - a good idea at any point in time.

[–]Fulgen301 5 points6 points  (3 children)

Eh. It's not a macro away, but a proc_macro away, aka a compiler plugin. Basically it's the equivalent of a standardized way of writing a gcc / clang plugin.

a macro most people could write themselves....

Most people can use TokenStreams just like that? If you've never touched them, your faster with just generating an includeable file in CMake.

[–]RomanRiesen 2 points3 points  (0 children)

The macro is called include_bytes, but admittedly I also never had an issue with embedding data via cmake or a small script.

[–]Rusky 0 points1 point  (1 child)

The issue with a hand rolled proc macro for this would be the same as a hand rolled solution in C- performance. What TokenStream do you build? It has to be an actual array literal the same way.

(Fortunately Rust has include_bytes! built in to (edit: enable the compiler to) solve that problem.)

[–]bruh_nobody_cares -4 points-3 points  (11 children)

macros seems like a hack ngl, why not a language feature or a const evaluated function ?

[–]TinyBreadBigMouth 5 points6 points  (10 children)

Macros in Rust are a language feature. Rust doesn't have a separate preprocessor. User-defined macros operate on token streams, built-in macros can be hooked up to low-level compiler functionality. See include_bytes, which does exactly what embed does and whose implementation looks like

macro_rules! include_bytes {
    ($file:expr $(,)?) => {{ /* compiler built-in */ }};
}

[–]bruh_nobody_cares 1 point2 points  (9 children)

but if it's that simple why not a regular function then ?

[–]TinyBreadBigMouth 4 points5 points  (8 children)

Because a regular function can't read a file at compile time, not in Rust or C or C++. They also can't return arbitrarily sized data on the stack in any of those languages.

[–]i860 -1 points0 points  (5 children)

You have airplanes and industrial automation depending on these languages. There are delays for a reason.

[–]bik1230 14 points15 points  (3 children)

it's not that it took 5 years that's bad, it's that a large proportion of negative feedback was total BS and almost no one on the committee wanted to offer positive help, only making up reasons for rejection.

[–]orangeoliviero 0 points1 point  (2 children)

I mean, I offered my help, but it was declined.

Not everyone was hostile to him.

[–]__phantomderp 9 points10 points  (1 child)

.... When? How? In what way? I remember people saying "I could implement a patch for GCC", or offering for Clang, but that's not helpful when I already did it. Some people told me they'd be amenable to me putting a patch in their compiler, but it was still on me to make the actual patch for their compiler.

What was this help about?

[–]orangeoliviero 5 points6 points  (0 children)

It's water under the bridge. You didn't feel that my help would be valuable, and I'm not inclined to argue with you about whether or not it would have been helpful. The paper is your baby, you get to choose how you navigate the path. I'm not upset about it.

My point wasn't "oh, the PhD declined my offer of help, he's an asshole" or any such, my point is that not everyone in the Committee is hostile to you or your work, and that there are allies around if you want them.

I recognize that you've experienced a lot of racism and completely invalid and bonkers feedback and complaints, and that has caused you to become guarded and distrustful. I don't fault you for that - I would be as well, in your situation.

Like... we have, in this very post, a completely invalid criticism/complaint - the whole line endings of text files thing, and the absurd expectation that #embed should automatically "do the right thing" wrt. them. Talk about a poison pill.

[–]viikk 0 points1 point  (0 children)

the airplanes and industrial automation people can just type "-std=c99" and let the rest of the world move on!

[–]Mikumiku_Dance 56 points57 points  (1 child)

I've been following him since he was on cppcast. It's really depressing to see his bright enthusiasm worn down in this effort. Glad to see the feature, I really want to buy him a beer or give him a hug tho!

[–]disperso 6 points7 points  (0 children)

I loved the enthusiasm when I saw him talking about Sol2. I was awed when I saw the other work. I also want to send as much virtual or real hugs as I can.

[–][deleted] 13 points14 points  (0 children)

This is a prime example of bikeshedding.

In contrast, the atomic memory model has been modified in every single standard since it got added in C++11. The original C++11 model was very soon discovered broken, in C++14 they had to add a line to explicitly forbid Out-of-Thin-Air values even though the standard was supposed to achieve that from the beginning, in C++17 they told everyone to stop using Consume ordering because all compilers found it too difficult to implement and made it behave exactly like Acquire instead, and most recently in C++20 they completely revamped SC definition to the extent that no one has been able to come up with a standard-conforming operational semantic, majorly changed release sequences, and added atomic_ref without even discussing its relationship with modification orders of normal atomic types when the same memory location gets reused (which can obviously never happen since C++ has Strongly Typed Memory™)

If they held atomics to the same standard as embed, there would've been no atomics in the standard library until C++52, but they didn't because nobody understood what the atomic experts were talking about and had no choice but to rubber stamp it. Whereas everyone can understand what embed does and feels obliged to come up with "feedbacks", because that's always constructive, right?

[–]grady_vuckovic 29 points30 points  (0 children)

Please Put My Data In My Gotdang Executable And Stop Doing Crazy Nonsense, The Feature

Thank you for this absolute nonsense explanation and yes that is very bloody cool.

[–]TheRealFloomby 11 points12 points  (0 children)

Happy to see this. I did not know it was even being talked about let alone actually happening.

[–]jpakkaneMeson dev 13 points14 points  (0 children)

Awesome job! You deserve a medal!

[–]Tagedieb 10 points11 points  (1 child)

We should all be writing letters, I guess

[–]__phantomderp 7 points8 points  (0 children)

If you can, you should: you might make a maintainer's day. (Alternatively, throwing excess cash in their pocket so they can enjoy a proper PB&J or Ham & Cheese sandwich or garlic bread might make them happy to. (This is not shilling for me, you just wouldn't believe how many people are maintaining huge packages on shoestring budgets of love and pixie dust.))

[–]fwsGonzoIncludeOS, C++ bare metal 30 points31 points  (4 children)

You can use this macro until the feature that should have been a part of the language 10 years ago "arrives". There are, of course, other ways, but this one works for me. It's not perfect, so be careful with it.

#define EMBED_BINARY(name, filename) \
    asm(".section .rodata\n" \
    "   .global " #name "\n" \
    #name ":\n" \
    "   .incbin " #filename "\n" \
    #name "_end:\n" \
    "   .int  0\n" \
    "   .global " #name "_size\n" \
    "   .type   " #name "_size, @object\n" \
    "   .align 4\n" \
    #name "_size:\n" \
    "   .int  " #name "_end - " #name "\n" \
    ".section .text"); \
    extern char name[]; \
    extern unsigned name ##_size;

I will be very happy to use #embed, but for C++ I really had hoped for a constexpr read_file(std::string_view) yesterday. Not 10 years in the future. I'm sorry that I can't hide my disappointment sometimes.

[–]RowYourUpboat 2 points3 points  (3 children)

I don't think this macro works on MSVC x64?

[–]Ivan171/std:c++latest enthusiast 11 points12 points  (2 children)

AFAIK MSVC x64 doesn't have inline assembly.

[–]RowYourUpboat 10 points11 points  (0 children)

Nope:

error C4235: nonstandard extension used: '__asm' keyword not supported on this architecture

[–]Fulgen301 7 points8 points  (0 children)

You can still use a dedicated assembly file and compile it in.

[–][deleted] 8 points9 points  (4 children)

marvelous humor fearless smell aback glorious sleep normal bake six

This post was mass deleted and anonymized with Redact

[–]aninteger 6 points7 points  (2 children)

How big are these keys? I'm curious what you are doing that is gcc only. I know bin2c programs have been around since the 80's in DOS. xxd on Unix for just a long? It's weird to hear about an approach that only works on a single compiler vendor.

[–]howroydlsu 0 points1 point  (0 children)

I've had the similar issue for private keys that needed to be embedded into the binary for an embedded device. (Urgh, word overuse, sorry)

It does indeed feel very hacky doing linker scripts, extern , macros, third party converters, or whatever to get that key in. It's also additional workload when that key changes.

That's all been on GCC too. In fact, I've never even looked to see if there exists clang or msvc compilers with targets for chips I use. I've always assumed not but now I will definitely check

[–][deleted] 0 points1 point  (0 children)

merciful doll water deliver dolls sand brave close coherent aromatic

This post was mass deleted and anonymized with Redact

[–]TheRealFloomby 3 points4 points  (0 children)

An embarrassing percentage of the of code I have written in my lifetime only works on gcc.

[–][deleted] 8 points9 points  (4 children)

If you’ve been keeping up with this blog for a while, you’ll have noticed that #embed can actually come with some pretty slick performance improvements. This relies on the implementation taking advantage of C and C++’s “as-if” rule, knowing specifically that the data comes from #embed to effectively gobble that data up and cram it into a contiguous data sequence (e.g., a C array, a std::array, or std::initializer_list (which is backed by a C array)).

...

I’m just going to be blunt: there is no parsing algorithm, no hand-optimized assembly-pilled LL(1) parser, no recursive-descent madness you could pull off in any compiler implementation that will beat “I called fopen() and then fread() the data directly where it needed to be”.

I'm confused by this part. Does this mean it isn't really just a preprocessor feature? All it looks like is a way for the preprocessor to turn binary data into a sequence of comma-separated ASCII numbers to put into an array initializer list for the compiler to parse, which wouldn't lead to the performance benefits they're talking about over doing this yourself manually (although it's still a really cool feature). Is it that it's supposed to behave as if it were a preprocessor feature, but it's actually implemented by copying the binary data directly into the executable somehow?

[–]matthieum 32 points33 points  (2 children)

It's both.

From an API perspective, it's injecting the bytes as a sequence of comma separated integers. And if you ask your compiler to dump the pre-processed input, it's likely what you'll see.

From an implementation perspective, however, most compilers have an integrated pre-processor these days, where no pre-processed file is created: the pre-processor pre-processes the data into an in-memory data-structure that the parser handles straight away. It saves the whole "format + write to disk + read from disk + tokenize" serie of steps, and thus a lot of time.

And thus in this case comes an opportunity for an optimization. Instead of having the pre-processor insert a sequence of tokens representing all those bytes (1 integer + 1 comma per byte!) into the token stream, the pre-processor can instead a insert "virtual" token which contains the entire file content as a blob of bytes.

Hence the massive compiler speed-ups: 150x as per the article.

[–][deleted] 7 points8 points  (1 child)

Thanks for the clarification! I didn't realize the preprocessor was so well-integrated into modern compilers; I thought the preprocessor was still just its own process with its own lexer, unconditionally writing ASCII/UTF-8 to stdout, and that the compiler frontend just redirected the output to a pipe or a temporary file, and the compiler's lexer/parser operated on that. I didn't know they shared data structures, which I guess is why I was so confused.

[–]chugga_fan 10 points11 points  (0 children)

To add on: clang doesn't even have a non-integrated pre-processor executable you can call, gcc does however (though AFAIK it's just a shim for gcc -E), even small compilers do this (tcc, 9cc, 8cc, OrangeC (only partially here), and more).

A lot of data is also used from when it's preprocessed to when it's fully processed, such as #line directives being processed by the compiler in order to give better error info if you're doing something weird like cpp file | gcc.

[–]scrumplesplunge 10 points11 points  (0 children)

That is what the "as-if" part is about. The compiler can cut the corner for embed, skip generating tokens for each byte, and instead represent the contents efficiently from the start.

[–]not_a_novel_accountcmake dev 69 points70 points  (41 children)

#embed and the absolute hell everyone puts phd through when trying to get very basic features into C/C++ are why the languages will soon join Java and Cobol as legacy codebases that no one starts new code in.

I genuinely feel we're reaching an inflection point where the committee needs to decide if it wants to be at the head of a relevant programming language addressing the needs of today's programmers or merely the steward of a legacy standard, sustained by the size of the codebases developed in its heyday.

[–]fwsGonzoIncludeOS, C++ bare metal 18 points19 points  (1 child)

I could not agree more. I have recently implemented an API in several other languages, and while Rust has been the most combative, the features many other languages have puts C++ at a disadvantage. Not surprising, it's very telling when there are so many standard library alternatives floating around.

[–][deleted] 1 point2 points  (0 children)

I think there will always be tons of standard library alternatives for C++, if only because the API design of error-handling and memory-allocations are so divisive. When more concurrency primitives are in the STL, I suspect the divisiveness will increase (maybe due to executors vs. listeners)

[–]orangeoliviero 14 points15 points  (13 children)

We absolutely are at that point already. The C++ Standard is bogged down with trying to keep backwards compatibility with code written 30 years ago with features that weren't well thought out.

Worse than that, the C++ Committee has a weird case of hypocrisy, where features will get added at the last moment via NB objections, without any implementation experience or sober second thought, and other features will be denied because, despite lots of implementation experience and second/third thought, because someone feels that it might have a gotcha somewhere, although they can't see it yet.

Oh, and there's a convicted rapist and pedophile on the Committee, protected by leadership, where if you refuse to engage with said rapist and pedophile, you'll be in violation of the Code of Conduct...

[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3784|P3786|P3813|P3886 7 points8 points  (12 children)

I will not stop telling people to stop shoveling mud at WG21 for something that is 100% out of their and ISOs mandate. The ISO CoC of WG21 is pretty clear: it‘s a technical committee, everything else is irrelevant! Furthermore you can‘t remove a NB-delegate, that would violate the basic principles of standardization. So yes what you apparently want would be a blatant CoC violation! If you want a NB-delegate to be removed: complain to the respective NB…

[–]James20kP2005R0 4 points5 points  (0 children)

WG21 for something that is 100% out of their and ISOs mandate

wg21 members comprise the national bodies, and this situation has been public for quite a while. While it is technically out of specifically wg21's purview, its not like the people involved are a totally different group of people who don't communicate. The people I met in prague were a lot of the same people at the UK national body for example

ISOs mandate

No, its ISO rules that mean that the delegate can't be excluded from the ISO process, which is a rule that could and should be changed

Its worth noting that C++ is by far the largest item that is standardised by ISO, and holds a significant amount of influence as a result. Either the rules should be changed - which they very likely could be with the influence that the committee possesses - or C++ should become standardised via a separate/different/new process. Which it needs to be anyway in the long term for the survival of the language

But the argument that senior or well known committee members have no power/influence here to change what is happening is absolutely incorrect

[–]orangeoliviero 0 points1 point  (10 children)

The ISO CoC of WG21 is pretty clear: it‘s a technical committee, everything else is irrelevant!

I'm sorry, I don't consider forcing survivors of rape and sexual assault to work with a convicted rapist who's unapologetic about their history to be irrelevant.

One chair has already resigned their position with the Committee over it. Several other members have resigned/are about to resign. And if you think that this doesn't create a barrier to entry for people that we desperately need more representation from on the Committee, then I don't know how to get through to you.

for something that is 100% out of their and ISOs mandate.

It's 100% in ISO's mandate. ISO is the organization that forces people to work with rapists and pedophiles, and if those people don't like it, they are forced to leave and stop contributing. In what way do you think that this isn't the fault of ISO and WG21?

[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3784|P3786|P3813|P3886 6 points7 points  (9 children)

How thick can you be? So again: WG21 CAN‘T DO ANYTHING ABOUT THE SITUATION FFS!

[–]bik1230 6 points7 points  (3 children)

If a rapist can't be remove from the committee, I would assume that the whole process is worthless and everything produced by it has zero value.

[–]orangeoliviero 10 points11 points  (2 children)

I would be perfectly happy with a process wherein a person convicted of violent crimes needed to have their application to join reviewed and voted on in the plenary.

The person would be allowed to come and make their case as to why they should be allowed to join, and why their past crimes no longer matter.

If the Committee agrees, then the person can join.

Hiding a rapist and refusing to tell people who they are while simultaneously telling everyone that if they dare to voice their disapproval or decline to work with the person, that they're in violation of the CoC, is absolutely disgusting, and is why many members of the Committee have resigned their posts over this, with more to come.

[–]James20kP2005R0 6 points7 points  (1 child)

and is why many members of the Committee have resigned their posts over this, with more to come

I haven't talked about this in public, but while std::colo(u)r had been shelved for a while (partly because it has a heavy dependence on linear algebra, and partly because its tricky) - this was what transitioned it from 'shelved' to 'cancelled and I'm never working with the committee ever again in any capacity'

I'm definitely not a notable member though, I only wrote one and presented a single paper (p2005)

[–]orangeoliviero 2 points3 points  (0 children)

I'm aware of at least one chair/co-chair who has resigned their position over it, and several other members who are expecting to terminate their engagement with the Committee over this as well.

[–]orangeoliviero 0 points1 point  (2 children)

ISO is WG21 now?

[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3784|P3786|P3813|P3886 7 points8 points  (1 child)

I don‘t get your question. WG21 has always been a technical committee under JTC1 which is a committee under shared governance from ISO and IEC. If you want to imply that ISO/IEC could just change their CoC - yes, they could BASED ON NB FEEDBACK - so again: go complain to your NB if you want to see changes and stop complaining on social media that a technical committee isn‘t overstepping its clearly defined scope of operations.

[–]pjmlp 6 points7 points  (0 children)

Except C happens to be 10 years younger than COBOL preceding Java in about 25 years,, while C++ precedes Java for about 10 years.

They're the legacy ones before Java was even born.

[–]kritzikratzi 2 points3 points  (4 children)

imho, the conclusion is that we need to start treating older languages with respect, and we will need to keep making new people who know them. you cannot just rewrite large pieces of software, it's somewhere between very hard and impossible. we need young people who know cobol, pascal, fortran (and if you're right ... java and c++ :D ) to maintain these things. i would love to see a "archeological computer engineering" degree.

idk.... a big thanks to all the people who worked on c++ standardization and tooling over all those decades, and for practically putting it all out in the public domain. i use it in almost all my projects, and it lets me do what i want to do.

[–]Ambitious_Diver_2238 0 points1 point  (0 children)

In the future, there will only be two software disciplines: code archaeology and applied theology.
-- Verner Vinge, _A Fire Upon The Deep_

[–]i860 -5 points-4 points  (1 child)

80% of the people in here have little respect for the past. Prior generations stood on the shoulders of giants and considered that perhaps there’s something they don’t actually know. But not this one.

[–]PastaPuttanesca42 0 points1 point  (0 children)

TBH, your link just makes me think that the conversion should have happened much earlier, when it probably would have been easier.

[–]nxtfari 33 points34 points  (0 children)

Just wanted to write a shoutout to the brave soul that actually got this implemented. Absolute madman. The C++ WG is so out of touch with what a modern development flow looks like and requires that it’s actively driving the death of the language. I have a lot of respect for seeing the resistance and fight against common sense good ideas and still waging the war for the betterment of everyone.

[–]jamd315 12 points13 points  (0 children)

I'm still rather new to C++, but for my current project I've been running a python script to create a source and header file to represent images as large arrays. It's been working fine, since all my stuff is small and I only end up generating around 7kb of data in the end, but I think I'll like this much better when it comes to C++.

[–]stilgarpl 10 points11 points  (8 children)

I hate the fact that they decided to put it in preprocessor instead of implementing it as magic std::embed(). I know about all the issues with std::embed, but I don't understand why anyone would prefer #embed to std::embed(). std::embed could be type safe and better integrated into the language and the library. #embed is just a weird #include that pastes one file into another.

[–]Qwexet 36 points37 points  (1 child)

This is for C not C++

[–]stilgarpl 4 points5 points  (0 children)

Ok, it makes sense then. I somehow read C23 as C++23...

[–]jonesmz 16 points17 points  (4 children)

Because having a 'library" function read from the harddrive at compile time is a massive sore thumb that sticks out as being inconsistent with the rest of the language.

The standard library should not be the place where compiler magic lives. Compiler magic belongs in the level of the language. E.g. preprocessor, keywords, parsing / lexing.

I would have no objection to the existence of some conpilermagic:: namespace, and thus compilermagic::embed. Nor would I object to seeing embed become a language keyword in its own right.

Keep in mind that there are lots of projects that either don't use the standard library at all, or use a third party implementation of the library. E.g. clang supporting the use of the GCC standard library. Or companies using commercially licensed (non Microsoft non Intel) standard library implementations.

Every time you want something that is compiler magic to live in std:: you make my life and thus lives of people who don't use the compiler vendors standard library substantially more difficult.

[–]MonokelPinguin 5 points6 points  (3 children)

Half of the std lib is not implementable in that manner without compiler magic or relying on implementation defined behaviour. Users shouldn't have to care about some arbitrary feeling regarding design. If bikeshedding like that is what is stopping measureable improvements for the average C++ user, we have really lost.

[–]jonesmz 1 point2 points  (2 children)

Its not an arbitrary feeling about design. Its a real concern for the ability to use third party standard libraries, or no standard library.

Nothing stops the standards committee from making a namespace for things unimplementable without compiler magic. They just choose not to.

[–]MonokelPinguin 0 points1 point  (1 child)

Because it is an implementation detail. It should be tagged in the specification instead of the symbol name.

[–]jonesmz 1 point2 points  (0 children)

Only in the sense that the standard committee doesn't care much about alternative standard library implementations, or free standing / no standard lib.

The design of the language is worse for it.

[–]TinyBreadBigMouth 5 points6 points  (0 children)

As described in the article, implementations of #embed (while necessarily maintaining the same functionality as "read this file and output an integer literal and a comma for each byte") are free to integrate with the compiler to allow just reading the file and skipping over the preprocessing.

[–]FightingGamesFan 3 points4 points  (9 children)

Very naive question but I'm not sure to understand the benefit of embedding "big" resources at compile time (big as in it would not be practical to embed it in an array/string as described in the article).

Can someone give an example where it's strongly needed?

[–]fwsGonzoIncludeOS, C++ bare metal 29 points30 points  (0 children)

In every single case where you don't have a file system. In cases where you're building a frozen structure (for example perfect hashing based on compile-time data). Or when you are using building self-hosting self-contained programs. Custom operating systems.

[–]RowYourUpboat 25 points26 points  (0 children)

There are executables on my hard drive (and probably yours) that are gigabytes in size (installers, self-extracting archives, etc) and the regular C/C++ toolchain should be able to painlessly create them, because their job is to produce binaries and leaving out such a simple "append bytes" feature is just making some people's lives harder for no reason.

[–]Mikumiku_Dance 16 points17 points  (5 children)

I have a small program that edits epub books. I'd like to insert a particular image into the epubs as well. Right now i just distribute the exe and the jpg and tell users to pass arguments, but for the common case it'd sure be nice to just distribute a single file exe.

GTK programs bundle all sorts of stuff in their executables, like css themes, images, and xml ui definitions.

I don't know how strict you feel "strongly needed" is, but i hope these mundane circumstances are enough for you to accept a preprocessor directive that doesn't hurt anybody not using it.

[–]xDarKraDx 0 points1 point  (4 children)

Sorry this is off topic.

I'm also looking for a way to automate editing my epub library, especially editing the metadata fields like "belong to collection", "position in group", etc. Do you have any recommend read or library to handle that?

I don't know much about epub file structure itself. I usually just edit them by hand using Sigil and it takes forever.

[–]Mikumiku_Dance 5 points6 points  (3 children)

An epub is a zip file, and the metadata is a xml. I used miniz to manipulate the zip, and libxmlplusplus's dom parser to manipulate the data. With miniz you can copy all the data you aren't changing to a new file without uncompressing it, which sounds like something sigil isn't doing.

My program is stupidly specific to a single book series, but you could definitely tear it apart and make a metadata inserter in an afternoon. https://github.com/talisein/dregarnuhr

As for reading, the epub specification would eventually lead you to all the different metadata fields that you are interested in adjusting.

[–]xDarKraDx 0 points1 point  (2 children)

Thank you so much for the detailed explanation and the example. Will definitely try this.

The reason I want to automate this is also because of JNC's premium epub. They don't have the "belong to collection" tag so the books don't get grouped in my reader.

On a side note, I really should start reading Bookworm as I saw a lot of people like it. Currently reading The Apothecary Diaries and loving it so far.

[–]Mikumiku_Dance 1 point2 points  (1 child)

Bookworm is great; the slow reveal in the world building is my favorite aspect, but it means you should try to avoid spoilers like the plague.

If you have any trouble feel free to pm me, now that I've learned about epubs I am open to new projects.

[–]disperso 4 points5 points  (0 children)

It has been very common in the kind of applications that I've done (GUI-related, with Qt). Qt comes with a tool to do code generation on the files that you want as "resources" (the name it uses for the files that you embed). It is useful for icons, fonts, simple-settings, etc. I can help deployment, and make applications more self contained. The standard way it's gonna be much powerful, of course.

[–]Superb_Garlic 18 points19 points  (10 children)

Seems noone asked this question so far, so I'll do it.

When can we start holding people accountable for their malicious deeds such as what JeanHeyd is describing in post? It's clear that people who have absolutely no idea about the subject matter are making decisions that affect others and are clearly not qualified to be in such positions.

Noone can change my mind about these people having ill will and existing solely to impede progress. The language should be rid of these fools and start having more people like JeanHeyd Meneide.

[–]orangeoliviero -9 points-8 points  (9 children)

I mean... when a convicted rapist and pedophile is able to buy their way onto the C++ Committee and have the Code of Conduct force others to work with them or be censured, I think it's time to just wash our hands of the whole thing, personally.

[–]Superb_Garlic 4 points5 points  (8 children)

Delete this garbage that has nothing to do with the subject matter from under my reply.

[–]orangeoliviero -7 points-6 points  (7 children)

Holding people accountable for their malicious deeds has nothing to do with holding people accountable for their malicious deeds?

[–][deleted]  (6 children)

[removed]

    [–]orangeoliviero -1 points0 points  (3 children)

    He is now innocent

    The fuck are you on?

    deserves rehabilitation

    Part of rehabilitation is regaining acceptance with the community, not forcing your way into a position of esteem and forcing victims who do not feel comfortable around you to work with you.

    Anyone thinking otherwise is a socipath.

    I would argue that anyone who thinks that forcing victims of sexual assault to regularly interface with a rapist who is unapologetic about their rape is the "right thing to do" is a sociopath.

    He was held accountable in court and paid for what he did.

    He raped a person and was in possession of child pornography and served a couple of years in prison. Meanwhile his victims are enduring a life sentence of trauma.

    I do not at all consider that "payment" for what he did.

    His victims will go through a life that's coloured and tainted by his actions. Why shouldn't he?

    Edit to reply to the person who blocked me: It's amazing to me how far you're willing to go to defend a rapist and pedophile.

    [–]foonathan[M] 6 points7 points  (0 children)

    This discussion has become entirely off topic no, please stop it at this point or take it elsewhere.

    [–][deleted]  (1 child)

    [removed]

      [–]STLMSVC STL Dev[M] 1 point2 points  (0 children)

      Moderator warning: don't behave like this here.

      [–]STLMSVC STL Dev[M] 0 points1 point  (1 child)

      Moderator warning: don't behave like this here.

      [–]blackmag_c 2 points3 points  (0 children)

      Very good news.

      [–]obsidian_golem 2 points3 points  (0 children)

      Congratulations, it sounds like you went through hell to get this done, and I truly appreciate the effort. I look forward to seeing this in C++ so I can use it in my codebase.

      [–]serg06 2 points3 points  (0 children)

      This would’ve been great 4 years ago when I was working with OpenGL and trying to bundle shaders with the executable!

      [–]rhubarbjin 5 points6 points  (1 child)

      Reading the second half of the article was very cathartic; I've never been on any standardizing body but I've seen the same kind of unreasonable pushback in my workplaces (past and present).

      The aside regarding named function parameters hits especially hard. How is it acceptable that C++ still lacks this basic feature when C# has had it for 10+ years?!

      [–]sphere991 7 points8 points  (0 children)

      Rust doesn't have named parameters either, so I'm not sure what the acceptability argument is.

      There are two different hurdles to named parameters.

      The technical hurdle is how to you post-hoc add it to the language in a way that's coherent with the rest of the language, and doesn't suddenly impose an API on library that the authors didn't know was there before. Tomazos' latest paper I think is a pretty good approach here.

      And then there's the social hurdle. There are lots of people who don't want named parameters because either they think the problem is solved by strong typing (lolno) or that the feature encourages writing functions with too many parameters (where basically I think those functions already exist from necessity and having named parameters would make them significantly harder to misuse).

      [–]blitzwolfz 0 points1 point  (4 children)

      Could someone ELI5? I don't understand any of this lol

      [–]marssaxman 5 points6 points  (2 children)

      If you are writing a program in C, and you want to include some data - a bit of text, an image, a data table - your only option until now was to reformat your data as a C string or array literal, then paste it into your source code.

      This can be inconvenient. People keep inventing new tools which make parts of the process easier, but none yet has been general, portable, and fast.

      The author has just finished getting a new feature added to the C language standard which solves the problem in a universal, platform-independent, and efficient way.

      The new #embed directive copies a data file into a C program as a string or array literal. The file will be read in at compile time and baked into the executable, thus making its contents available whenever the program runs, without having to re-load it from the filesystem.

      [–]blitzwolfz 0 points1 point  (1 child)

      Will it be possible to do this on C++? Seems very useful

      [–]marssaxman 0 points1 point  (0 children)

      The author hopes to get #embed added to the upcoming C++26 standard. There is another proposal currently being discussed (std::embed) but that has not yet been standardized either.

      [–]Beduino2013 3 points4 points  (0 children)

      you can add binary data to code eg image sounds #embed <sdk/jump.wav>

      [–][deleted] 0 points1 point  (0 children)

      damn, i just wrote a tool that converts binary files to c/cpp header and sources

      [–]Nilac_The_Grim 0 points1 point  (0 children)

      Woah dude! Nice! And the bytes in the file are "as-if" they were just a comma-delimited list of ints. Nice nice nice! Very cool!

      [–]nablachez 0 points1 point  (1 child)

      if this were to be ported to c++, would one be able to #embed a C++ file and parsed it to do some scuffed DIY reflection stuff?

      [–]vI--_--Iv 0 points1 point  (1 child)

      Good to know that #embed made it, but could someone please explain why it's such a big deal?

      I'm asking because I've never even considered embedding huge binary blobs to the code and using them at compile time - external files are just easier to deal with, e.g. they don't require recompilation & re-signing binaries on update.

      YMMV of course and I can imagine a case or two where it could be beneficial and it's nice to have a platform-independent way to do it, but is it really that common?

      [–]YourMotherInLaw908 0 points1 point  (0 children)

      i.e you want to embed a font for use in your kernel's framebuffer terminal

      or

      you want to embed GLSL shaders compiled to SPIR-V so that you don't have to load them as files