Hacker News new | ask | show | jobs
by spacechild1 29 days ago
> That's because the default mode for compilers is to just shut up and compile this throw away code.

That's just not true. Compilers do issue certain warnings by default and they even treat some warnings as errors. See https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

> ?? Uninitialized variables are also serious issues and also undefined behaviour.

Oh my, I meant to write "unused variables" facepalm. Uninitialized variables are of course a serious issue.

So back to my original point: you said that warnings in C are always a serious thing, but that's not really true. Warnings can range from more or less harmless to very serious. In fact, compilers recognize this issue by upgrading certain warnings to errors by default. See again my link to the GCC 14 post: https://gcc.gnu.org/gcc-14/porting_to.html.

1 comments

> That's just not true. Compilers do issue certain warnings by default and they even treat some warnings as errors.

Because some warnings are just believed to be more serious, than others.

> In fact, compilers recognize this issue by upgrading certain warnings to errors by default.

Which I interpret as a culture shift, due to people complaining about it and also because the contemporary meaning and expectation of warnings for programming languages has shifted.

> Because some warnings are just believed to be more serious, than others.

Yes, that is my entire point. For some reason you were arguing against it.

I didn't intend to.

> Also, let's not forget that implicit casts between unrelated pointer types is only a warning in C.

I intended to argue against the "only a warning", because the meaning of a warning in C is something very serious. That is different from more modern languages, who may use this to inform you that you are no longer writing idiomatic code. Of course there are also exceptions, that you often need to enable explicitly. But the fact that something is a warning in C, doesn't mean it's nothing serious, quite the opposite. That's my point.

But you can't argue that a warning is less severe than a hard compiler error. Warnings can be supressed or ignored.

You were right to call out that the C standard only talks about diagnostics and the actual implementation is left to the compilers, but I don't think it really changes the actual argument I've been trying to make, namely that - unlike in C++ - implicit incompatible pointer casts are not a guaranteed compiler error.

In don't think this is required in C++ either.