3 ms·
> There are a shocking number of ways to accidentally create nondeterministic output when doing C/C++ development. One of the easiest is to use the builtin __DA
by lisper 4mo ago
> There are a shocking number of ways to accidentally create nondeterministic output when doing C/C++ development. One of the easiest is to use the builtin __DATE__ and __TIME__ macros to stamp a build with the time the compiler was executed at:
Am I missing something here? Yes, if you use a feature that intentionally inserts the build time and date into the code, the every build is going to be different. That's the whole point of these macros. It's a feature. If you don't want that behavior, don't use that feature.
- xena 4mo agoSurprisingly, cherry-picked examples to prove a point are cherry-picked examples to prove a point.
- fasterthanlime 4mo agoI think the intentional part is that you want to print the date and time something's been compiled, and the accidental part is that you suddenly made your build non-reproducible. But usually the realization follows the initial intent by several weeks, if not months! Your comment shines as the embodiment of hindsight is 20/20.
- lisper 4mo ago> the accidental part is that you suddenly made your build non-reproducible But that's exactly what I don't get. How can that be considered "accidental"? How can any thinking person not realize that putting the build time into the compiled image will make every build different because, you know, different builds happen at different times? Has software engineering really been dumbed down so much that this is not immediately obvious? It feels like a mechanic doing an oil change and being surprised by having all the oil drain out if they neglect to put the drain plug back in.
- Neywiny 4mo agoWith you on this especially because somebody I know asked me to help change their oil and they hadn't even considered there being waste oil to dispose of
- NobodyNada 4mo agoThe engineer who wants the build to be reproducible and the engineer who wants to have the build time in the compiled binary may not be the same person.
- lisper 4mo agoSure, but that is a completely different issue. People have mutually-conflicting goals on occasion. That is a Thing That Happens, but it is a very different phenomenon than being surprised by the obvious fact that putting a time stamp on your build makes that build non-reproducible.
- Moldoteck 4mo agobc you may want to have time in the build, but to some, this is just magic. They don't think about potential consequences of using such instruments
- eddd-ddde 4mo agoI don't think these kind of features belong in a compiler. If you want a stamp then pass it in to your compiler invocation via explicit defines. You might accidentally end up including it transitively and suddenly your binary is nondeterministic.
- yapfrog 4mo ago"One of the easiest" It's meant to be a trivial counterexample. Like saying "-1" to the claim "there's no number smaller than 0" to someone who's not familiar with math, the author is saying "build-dependent macros" to the claim "compilers are deterministic" to someone who might not be familiar with compilers.
- lisper 4mo agoA trivial counterexample to what? The antecedent of "one of the easiest" was "ways to accidentally create nondeterministic output." One even the most charitable reading I can muster that still seems to me to presume some pretty abject stupidity.
- eyelidlessness 4mo agoA trivial counter example to the intuition one might have that compilers likely produce deterministic output. It’s directly responsive to the exchange between Aoi and Numa above, wherein Aoi expresses exactly that intuition. Of course, those are characters playing out a question less familiar readers might ask. Presumably the intent is to make this content accessible to a wider audience, using an obvious example to introduce the concept without requiring much background knowledge.
- avadodin 4mo agoUsually, the person making the decision to add this is not in the same company or even the same time–space continuum as the victim of it. In a parallel non–Euclidean dimension, perpetrators go the other way and have their victims build with -j1 reproducible builds.