← Back to context

Comment by leni536

9 hours ago

Undefined means that the ISO C doesn't define the behavior. An implementation is free to do so.

If they do, that is no longer an implementation of C. It is a dialect of C, and there are many (GNU C being the most popular), but there are real drawbacks to using dialects.

This is in contrast to the other category that exists, which is "implementation-defined".

  • > If they do, that is no longer an implementation of C.

    This is plain wrong. Undefined behaviour, means the C standard specifies no restriction on the behaviour of the program, which is what the implementation chooses to emit. An implementation can very well choose to emit any program it pleases, including programs that encrypt your harddisk, but also programs that stick to well defined rules.

    • Sure, but the point is that code written against such a compiler is not C and is not portable. It is written in a dialect of C, and that comes with drawbacks.

      Writing C (or any language) means adhering to the standard, because that's the definition of the language.

      3 replies →

  • The thing is that the actual compiler behaviour matters more for real-world projects than what the C standard says. E.g. the C standard was always retroactive, it merely tried to reign in wildly different compiler behaviour at the time when the standard was new. It mostly succeeded, but still the most useful C and C++ compiler features are living in non-standard extensions.

    • Unaligned access being fine in one architecture, but not in others would create separate dialects, regardless of being blessed by ISO C.

      Just don't do unaligned access, it's a dialect that doesn't exist currently, and should never exist.