Groups | Search | Server Info | Login | Register


Groups > comp.compilers > #3684

Re: Undefined behaviour in C23

From anton@mips.complang.tuwien.ac.at
Newsgroups comp.compilers
Subject Re: Undefined behaviour in C23
Date 2025-08-22 17:16 +0000
Organization Compilers Central
Message-ID <25-08-010@comp.compilers> (permalink)
References <25-08-002@comp.compilers> <25-08-003@comp.compilers> <25-08-005@comp.compilers> <25-08-007@comp.compilers> <25-08-008@comp.compilers>

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:
>On 21/08/2025 21:53, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>> UB (both definitions) is an essential part of all programming languages
>>> - after all, if you have a bug in your code, you have UB, and no
>>> programming language has made it impossible to write bugs in your code.
>>> C just has some things that are undefined in C but defined in some other
>>> languages, and it is a bit more open and honest about UB than many
>>> language definitions.
>>
>> No, a bug in your code is not necessarily undefined behavior.  It could
>> easily be code whose behavior is well defined by the language standard,
>> but that behavior isn't what the programmer intended.
>
>
>When I write code, /I/ define what the behaviour of the code should be.
>A bug in the code means it is not acting according to my definitions -
>it is UB.

Yes, Humpty Dumpty.  Meanwhile, the rest of the world says that a
program exercises undefined behaviour when the *programming language*
specification does not define what the program does (or explicitly
undefines it), and calls programs incorrect (or, colloquially, buggy)
that do not behave as the *program* specification or requirements
demand; a buggy program may be defined according to the programming
language specification; e.g., I believe that the following program is
defined according to one of the C standards:

#include <stdio.h>

int main(void)
{
  puts("B");
}

If the specification of the program is to print "A" followed by a
newline, the program is incorrect, even though its behaviour is
defined.

A correct program may be undefined according to the programming
language specification (see Kaz Kylheku's examples).

Which brings us to your claim:
>>> UB (both definitions) is an essential part of all programming languages

This is nonsense.  If the programming language defines the behaviour
of all programs it accepts, and rejects all the others, it does not
have undefined behaviour.  As an example, Java tries to live up to an
even higher standard (no implementation-dependent behaviour aka "write
once, run everywhere"), but I am not sure if it succeeds in that.

- anton
--
M. Anton Ertl
anton@mips.complang.tuwien.ac.at
http://www.complang.tuwien.ac.at/anton/

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Undefined behaviour in C23 Martin Ward <mwardgkc@gmail.com> - 2025-08-20 14:06 +0100
  Re: Undefined behaviour in C23 Kaz Kylheku <643-408-1753@kylheku.com> - 2025-08-20 18:33 +0000
    Re: Undefined behaviour in C23 David Brown <david.brown@hesbynett.no> - 2025-08-21 15:02 +0200
      Re: Undefined behaviour in C23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-08-21 12:53 -0700
        Re: Undefined behaviour in C23 David Brown <david.brown@hesbynett.no> - 2025-08-22 17:58 +0200
          Re: Undefined behaviour in C23 anton@mips.complang.tuwien.ac.at - 2025-08-22 17:16 +0000
          Re: Undefined behaviour in C23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-08-22 15:11 -0700
            Re: Undefined behaviour in C23 David Brown <david.brown@hesbynett.no> - 2025-08-23 16:55 +0200
              Re: Undefined behaviour in C23 Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-08-23 15:58 -0700
              Re: Undefined behaviour in C23 James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-08-25 22:13 -0400
                Re: Undefined behaviour in C23 James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-08-26 13:41 -0400
                Re: Undefined behaviour in C23 Michael S <already5chosen@yahoo.com.dmarc.email> - 2025-08-26 22:28 +0300
                Re: Undefined behaviour in C23 James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-08-26 16:53 -0400
  Re: Undefined behaviour in C23 anton@mips.complang.tuwien.ac.at - 2025-08-21 05:44 +0000
    Re: Undefined behaviour in C23 David Brown <david.brown@hesbynett.no> - 2025-08-22 18:42 +0200
      Re: Undefined behaviour in C23 anton@mips.complang.tuwien.ac.at - 2025-09-06 17:15 +0000

csiph-web