News for hackers. Stuff that matters.
Re:C/C++ vs. Rust Performance by MaxBarraclough on Sunday November 01, 2020 @01:19PM (#24961331)
Why's that? C has a few features that C++ lacks, but it's possible to get by fine without using any of them.

The Lua interpreter is written in a subset of C so that it also compiles fine as C++. Or, if you prefer, in a subset of C++ so that it compiles fine as C.

https://www.lua.org/pil/24.1.html

Re:C/C++ vs. Rust Performance by josefx on Sunday November 01, 2020 @01:30PM (#24961401)
Something as simple as malloc requires a cast in C++ when it is not needed in C, so type errors for even simple code.
Re:C/C++ vs. Rust Performance by MaxBarraclough on Sunday November 01, 2020 @01:52PM (#24961542)
What type errors? Do you mean that, to get it to compile as C++, you have to add an explicit cast? That isn't a significant burden.

Requiring explicit casts, and forbidding implicit conversions, reduces the odds of being surprised by an unwanted conversion. There's a good argument to be made for adding explicit casts to C code even when the language doesn't require them. GCC's -Wconversion flag can help with this.

Re:C/C++ vs. Rust Performance by josefx on Sunday November 01, 2020 @02:22PM (#24961783)
> What type errors? Do you mean that, to get it to compile as C++, you have to add an explicit cast?

Yes.

> That isn't a significant burden.

But once you do it your "C" code is littered with a lot of unnecessary casts that increase the verbosity of the code and could hide errors. With pre C99 code it would also hide default int errors if the include for malloc gets lost at some point.

Re:C/C++ vs. Rust Performance by MaxBarraclough on Sunday November 01, 2020 @02:36PM (#24961881)
> and could hide errors

How? As I said, the stricter rules of C++ result in fewer type-conversion errors than C's permissive rules. That's the reason for C++'s stricter rules, and it's the reason Ada is even stricter.

As an example, consider

    a = b = c;
In a languages with permissive rules about implicit conversions, you have to inspect the variables' types to determine whether this statement is equivalent to

    b = c;
    a = c;
(Even ignoring OOP, that is.)

> With pre C99 code it would also hide default int errors if the include for malloc gets lost at some point.

Wouldn't it just fail to compile if you're missing a required header?

edit steveklabnik linked to [0] so I see what you mean now. I think that's a valid point.

[0] https://stackoverflow.com/a/605858/

Re:C/C++ vs. Rust Performance by ByteJockey on Sunday November 01, 2020 @02:04PM (#24961643)
But the conversion of the result of a malloc call is neither surprising nor unwanted.

There's also no ambiguity. You've already explicitly defined the variable's type at that point.

Re:C/C++ vs. Rust Performance by MaxBarraclough on Sunday November 01, 2020 @02:21PM (#24961772)
There's very little harm in making the conversion explicit. It's more verbose, but it's also more explicit, which is a good thing.

There is harm in implicit conversions catching the programmer unawares. This is a fairly significant cause of bugs in C code, and it's why C++ uses stricter rules, requiring you to always make these conversions explicit, even when using malloc.

Re:C/C++ vs. Rust Performance by steveklabnik on Sunday November 01, 2020 @02:24PM (#24961796)
There is a significant group of folks that believe it is actively bad. I don't write enough C these days to have a stance, personally, but https://stackoverflow.com/questions/605845/do-i-cast-the-res...
Re:C/C++ vs. Rust Performance by ncmncm on Sunday November 01, 2020 @10:34PM (#24964605)
There is a significant group who are wrong about literally anything one can think of. How vocal they are about it does not correlate with much.
Re:C/C++ vs. Rust Performance by ByteJockey on Sunday November 01, 2020 @10:45PM (#24964666)
But that fact does not get us any further towards figuring out who is wrong. It merely tells us that people disagree.
Re:C/C++ vs. Rust Performance by ncmncm on Sunday November 01, 2020 @11:13PM (#24964773)
People still coding C can usually be counted on to be wrong.
Re:C/C++ vs. Rust Performance by ByteJockey on Sunday November 01, 2020 @10:55PM (#24964696)
You're not entirely wrong, but in the context of the specific example given (malloc), it's about as implicit as c++'s auto keyword, it just obscures type information on the right side instead of the left side of the assignment from the programmer.

I would also argue that there's a hard to quantify harm in making code more verbose. More visual noise makes it harder to parse what's going on. Sure, one redundant cast isn't going to kill you. But many sources of repetition across an entire code base eventually turn it into a slog where the parts you want are obscured by useless noise.