Hacker News new | past | comments | ask | show | jobs | submit login

There's no contract. Nobody ever shared a piece of paper saying "your software must not use UB".

The closest thing to a "contract" a language has is training material and reference books. And guess what, nearly all of C material mostly ignore UB, because enumerating it all is completely impractical even for reference books.

Most of the C software in use on the wild was created before the hyper-optimization trend of C compilers, when your program did mostly what you said, and if what you said is undefined, it would still behave in some way that is close to a literal reading of the code. For most of the C software that exists, the modern treatment of UB is a huge post-facto unilateral contract change.




The C specification is the contract between you and the compiler.


Yep. The creators of the standard spoke to this:

"The three-fold definition of compliance is used to broaden the population of conforming programs and distinguish between conforming programs using a single implementation and portable conforming programs.

A strictly conforming program is another term for a maximally portable program. The goal is to give the programmer a fighting chance to make powerful C programs that are also highly portable, without demeaning perfectly useful C programs that happen not to be portable. Thus the adverb strictly.

By defining conforming implementations in terms of the programs they accept, the Standard leaves open the door for a broad class of extensions as part of a conforming implementation. By defining both conforming hosted and conforming freestanding implementations, the Standard recognizes the use of C to write such programs as operating systems and ROM-based applications, as well as more conventional hosted applications. Beyond this two-level scheme, no additional subsetting is defined for C, since the Committee felt strongly that too many levels dilutes the effectiveness of a standard.

Conforming program is thus the most tolerant of all categories, since only one conforming implementation need accept a program to rule it conforming. The primary limitation on this license is §2.1.1.3. "

It turns out it's not an all-or-nothing thing. Not being "strictly conforming" is not a "breach of the contract" by the developer, and thus license for the compiler to do anything they want.

See also:

"Existing code is important, existing implementations are not. A large body of C code exists of considerable commercial value. Every attempt has been made to ensure that the bulk of this code will be acceptable to any implementation conforming to the Standard. The Committee did not want to force most programmers to modify their C programs just to have them accepted by a conforming translator. "

http://port70.net/~nsz/c/c89/rationale/a.html


It's not a contract if you can't expect one of the parties to have read it.

Compiler developers do not need a contract with the users. No compiler team works with that impression. No compiler user expects one either.

But if you want to use it to justify some impractical behavior, well, both your justification is a complete fabrication, and justifying it is completely meaningless. It doesn't become practical because you have some sociological theory.


You seem to be using the legal definition of 'contract'.

We're using the computer science definition, which is simply "assuming it's correctly implemented, if you feed this program Foo, it'll do Bar".


You haven’t read the C standard? It’s not that long and fairly understandable.

Plus you can go around telling people true things like “malloc() can’t be implemented in standards-compliant C” and they’ll get mad at you.


Which compiler team doesn't take the C standard seriously?

And the C standard is by definition a contract between the implementation and its users.


If you actually read the standard, you will find out that this turns out not to be the case.

The C standard is (or maybe was, quite possible that the compiler mafia removed that bit as well) very clear that standards compliance is not sufficient for a compiler to be "fit for purpose".


So the contract includes a "this contract does not guarantee that the product is fit for purpose" clause. So what? Many contracts do that; i.e. it's a fairly typical trait of contracts.


But they really meant it.

See also the different conformance levels and the rationale given for them.

http://port70.net/~nsz/c/c89/rationale/a.html


I have read the standard, and I don't believe your comment to be true. Can you point out the exact section that backs up what you're saying? (And if you say the "compiler mafia" did remove it, then can you point to an older version that says it?)


Alas, I can no longer find it. :-(

However, the rationale is quite clear on most of this.

http://port70.net/~nsz/c/c89/rationale/a.html


I didn't say it's the contract; I said it's a contract.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: