News for hackers. Stuff that matters.
Re:C++ Pattern Matching Proposal [pdf] by atilaneves on Friday January 03, 2020 @01:40PM (#21948902)
> the transparency and predictability of what machine code gets generated from the source code.

This gets said a lot, but unless you're writing C code for a microcontroller (or a PDP11), that isn't even close to being true.

> When you write "a + b", you won't end up with kilobytes of machine code just because someone in some header overloaded the + operator.

You can't overload "+" for integers or floats. If you add two numbers together, you get what you expect, always. If they're not numbers, and somehow you expected `a + b` to work without an overloaded operator, then I don't know what to say.

> You want a function, you define that function.

Then you define it again for another type, then again, then again...

Then you write a macro and now your colleagues hate you.

> All of these constructs, should they be added to the language, will result in a compiler generating heaps of code from a simple code snippet

Not necessarily.

Re:C++ Pattern Matching Proposal [pdf] by phkahler on Friday January 03, 2020 @09:07PM (#21952283)
>> You can't overload "+" for integers or floats. If you add two numbers together, you get what you expect, always. If they're not numbers, and somehow you expected `a + b` to work without an overloaded operator, then I don't know what to say.

You can't overload the + operator in C. If you see a+b in code you know it is adding two numbers (or a compile error). In C++ it could be doing anything. In C you may question the size or type (fp vs int) of the variables, but not the operator. + does addition. Always.

Re:C++ Pattern Matching Proposal [pdf] by huhtenberg on Friday January 03, 2020 @04:35PM (#21950623)
> This gets said a lot,

No, this actually doesn't get said a lot, however the simplicity of C compilation semantics is one of its biggest strengths.

> ... but unless you're writing C code for a microcontroller (or a PDP11), that isn't even close to being true.

Do humor us with an example of a C code that compiles into something that is "not even close" to what you'd reasonably expect.

Re:C++ Pattern Matching Proposal [pdf] by umanwizard on Friday January 03, 2020 @07:12PM (#21951736)
Re:C++ Pattern Matching Proposal [pdf] by huhtenberg on Saturday January 04, 2020 @05:09AM (#21954014)
How is basic loop unrolling is "not even close" to the expected result when you explicitly ask for optimization with O3?
Re:C++ Pattern Matching Proposal [pdf] by umanwizard on Saturday January 04, 2020 @08:58AM (#21954916)
This isn’t basic loop unrolling; it’s replacing an entire loop with a closed form mathematical formula.
Re:C++ Pattern Matching Proposal [pdf] by huhtenberg on Saturday January 04, 2020 @09:54AM (#21955152)
It's a form of loop unrolling. Regardless of the term, this is still very much in the ballpark of what you'd expect when asking for optimization.