Comment by tialaramex

6 months ago

Here's how Bjarne describes that first C++ program:

"a simple program that writes every unique line from input to output"

Bjarne does thank more than half a dozen people, including other WG21 members, for reviewing this paper, maybe none of them read this program?

More likely, like Bjarne they didn't notice that this program has Undefined Behaviour for some inputs and that in the real world it doesn't quite do what's advertised.

The collect_lines example won't even compile, it's not valid C++, but there's undefined behavior in one of the examples? I'm very surprised and would like to know what it is, that would be truly shocking.

  • Really? If you've worked with C++ it shouldn't be shocking.

    The first example uses the int type. This is a signed integer type and in practice today it will usually be the 32-bit signed integer Rust calls i32 because that's cheap on almost any hardware you'd actually use for general purpose software.

    In C++ this type has Undefined Behaviour if allowed to overflow. For the 32-bit signed integer that will happen once we see 2^31 identical lines.

    In practice the observed behaviour will probably be that it treats 2^32 identical lines as equivalent to zero prior occurrences and I've verified that behaviour in a toy system.

"Undefined behavior" is not a bug. It's something that isn't specified by an ISO standard.

Rust code is 100 percent undefined behavior because Rust doesn't have an ISO standard. So, theoretically some alternative Rust compiler implementation could blow up your computer or steal your bitcoins. There's no ISO standard to forbid them from doing so.

(You see where I'm going with this? Standards are good, but they're a legal construct, not an algorithm.)

  • > "Undefined behavior" is not a bug. It's something that isn't specified by an ISO standard.

    An ISO standard? According to who, ISO?

    • Yeah, legal constructs are not actually real and are based on circular logic. (And not just in software, that's a property of legal constructs in general.)

      Your point is what?