Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Making syntax errors UB instead of specifying that the program must refuse to compile may seem unfortunate, but it does have some justification: it allows implementations to add extensions to the language and still claim compliance with the standard. If the standard mandated that any syntax not allowed by the standard must cause a compilation error, any compiler adding extensions to C syntax would be in breach of the standard.


The standard could mark that behaviour as implementation defined instead of undefined.

But it's really a non-issue: compilers like GCC don't claim to be standards compliant in all modes and with any combination of options. They are happy enough to have some combination of command line options that make them behave according to a specified standard.


I don't see any problem with syntax not allowed by the standard being a breach of the standard.


And you don't see any problem with extensions being prohibited?


No, I don't. I think that extensions are extensions which by definition are not part of the standard.

Compilers should allow extensions, but the standard does not necessarily have to. I do not say it should be done this way, but it is perfectly possible to define a strict standard and leave extensions out of it.


And that's what's happening in practice for some features.

GCC has a ton of options, and only a few of the myriad combinations give you a compiler that behaves strictly according to one of the C standards. And that's just fine.

In fact, compiler vendors experimenting, even in ways that are not allowed by the standard, is one of the main avenues to come up with new ideas for how to evolve the standard.

In fact, minor variations on semantics that are not allowed under the standard are probably more in spirit with C, than eg feeding the whole source file to a Python interpreter, if there's any string literal anywhere in the file that's not closed on the same line.

The former violates the standard, the latter complies.


That makes sense.




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

Search: