• Re: question about nullptr

    From Kaz Kylheku@21:1/5 to Thiago Adams on Sat Jul 6 12:54:26 2024
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use
    NULL).

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kaz Kylheku on Sat Jul 6 15:07:11 2024
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    One practical advantage of adding a named entity (with a value of 0)
    was to easily grep (find) appearances of this value in source code.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John McCue@21:1/5 to Thiago Adams on Sat Jul 6 12:33:11 2024
    Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    I avoid the use of new c items because I want full
    portability. Some systems may have older compilers.

    I am asking because I think I will keep using NULL.

    I will do the same

    <snip>

    --
    [t]csh(1) - "An elegant shell, for a more... civilized age."
    - Paraphrasing Star Wars

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Janis Papanagnou on Sat Jul 6 14:04:01 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use
    NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always
    use the NULL macro in both C and C++ code.

    [*] now obsolete.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to Kaz Kylheku on Sat Jul 6 14:51:19 2024
    On 06/07/2024 13:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use NULL).


    Using actual zero for a pointer value is crass. This wouldn't work for
    example:

    char *p = 3;

    Nor this:

    int a = 0;
    char *p = a;


    Although this does:

    char *p = 3/4;

    And this:

    enum {a=42, b=a};
    char *p = a-b; // or a&1, but not a&2

    It walks all over the language's type system, such as it is.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Scott Lurndal on Sat Jul 6 16:42:05 2024
    On 06.07.2024 16:04, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee.

    Yes, but a 0 pointer value has not the meaning of an int value 0.

    Janis

    I always
    use the NULL macro in both C and C++ code.

    [*] now obsolete.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to Thiago Adams on Sat Jul 6 10:39:57 2024
    On 7/6/24 7:49 AM, Thiago Adams wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    I am asking because I think I will keep using NULL.

    I like nullptr semantics but I don't like to introduce new element
    (nullptr) inside the code with no guarantee that the code will not mix
    both.

    In the past we also didn't have a guarantee we are not mixing 0 or NULL.

    I think the best scenario for a team guideline would be a style warning
    if 0 or nullptr is used and NULL to be defined as nullptr in a C23
    compiler.


    The (small) problem with 0 or NULL being use is that in a context where
    you THINK you are passing a pointer, but the function actually is taking
    an integer value, 0 or NULL (defined as a 0) passes the syntax check.

    If C23 REQURIED NULL to be defined as nullptr, then NULL would have been
    used, but as far as I know, it is still allowed to be defined as 0
    (unless you also have POSIX compatibility).

    With POSIX Compatibility, where NULL must have the type of (void*) you
    also avoid the possible error, and thus the desire to use nullptr.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Sat Jul 6 16:45:14 2024
    On 06.07.2024 16:42, Janis Papanagnou wrote:
    On 06.07.2024 16:04, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee.

    Yes, but a 0 pointer value has not the meaning of an int value 0.

    (Probably badly worded.)

    I meant; the internal binary representation of a 0 pointer value
    has not necessarily the internal binary representation of an int
    value 0. (So you could use it also in architectures like the one
    you mention.)

    Janis


    I always
    use the NULL macro in both C and C++ code.

    [*] now obsolete.



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Richard Damon on Sat Jul 6 18:57:08 2024
    On 06/07/2024 16:39, Richard Damon wrote:
    On 7/6/24 7:49 AM, Thiago Adams wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    I am asking because I think I will keep using NULL.

    I like nullptr semantics but I don't like to introduce new element
    (nullptr) inside the code with no guarantee that the code will not mix
    both.

    In the past we also didn't have a guarantee we are not mixing 0 or NULL.

    I think the best scenario for a team guideline would be a style
    warning if 0 or nullptr is used and NULL to be defined as nullptr in a
    C23 compiler.


    The (small) problem with 0 or NULL being use is that in a context where
    you THINK you are passing a pointer, but the function actually is taking
    an integer value, 0 or NULL (defined as a 0) passes the syntax check.

    If C23 REQURIED NULL to be defined as nullptr, then NULL would have been used, but as far as I know, it is still allowed to be defined as 0
    (unless you also have POSIX compatibility).

    With POSIX Compatibility, where NULL must have the type of (void*) you
    also avoid the possible error, and thus the desire to use nullptr.

    I hope that defining NULL as nullptr will become common - but I would be surprised to ever see it being required by C standards.

    The ideal would be for C libraries to define NULL as nullptr and for C compilers to support a flag like gcc's "-Wzero-as-null-pointer-constant" warning (it is currently C++ only). Then people can easily eliminate
    any mixup between integer 0 and null pointer constants by using that
    flag and either NULL or nullptr, according to taste. (And those who
    don't want such checks, are not required to change.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Tarasevich@21:1/5 to Scott Lurndal on Sat Jul 6 10:50:22 2024
    On 07/06/24 7:04 AM, Scott Lurndal wrote:

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always use the NULL macro in both C and C++ code.


    But that achieved absolutely nothing over using plain `0` in the source
    code.

    The `NULL` you used was still defined as `0` (in C++ libs) and 0 or
    `(void *) 0` (in C libs).

    --
    Best regards,
    Andrey

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to Scott Lurndal on Sat Jul 6 19:20:15 2024
    On 06/07/2024 15:04, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>> NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always use the NULL macro in both C and C++ code.


    You can ignore that requirement and just use all-bits-zero (in memory,
    not just in C source code). After all, the only thing you might want
    hardware support for is trapping a dereference of a NULL value.

    Presumably it was more of an ABI thing where all languages/compilers
    complying with it had to use the same NULL value, so the choice could
    have been made there.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to Chris M. Thomasson on Sat Jul 6 17:04:59 2024
    On 7/6/24 4:23 PM, Chris M. Thomasson wrote:
    On 7/6/2024 7:04 AM, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

        char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that
    use
    NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee.  I
    always
    use the NULL macro in both C and C++ code.

    Where:

    void* x = 0;

    Should be x = 0xc0eeeeee, right?


    Maybe when the representation of x is examined by reinterpreting it as
    an array of character types (like unsigned char).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Scott Lurndal on Sat Jul 6 23:14:40 2024
    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>> NULL).

    We also used 0 as "universal" pointer value regularly without
    problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe
    because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer
    "really" is on some hardware, 0 must work in C, including in comparisons
    with == and !=. You can have

    void *ptr = 0;
    if (ptr == 0) ...

    being true and also

    memcmp(&ptr,
    &(union { unsigned int u; void *p; }){ .u=0xc0eeeeee }.p,
    sizeof ptr) == 0

    being true.

    [*] now obsolete.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Janis Papanagnou on Sat Jul 6 22:11:02 2024
    On 2024-07-06, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use
    NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Instead of inventing a new keyword "nullptr", the C++ people should have
    made the 0p and 0P tokens have that meaning.

    In the preprocessing phases, 0p and 0P are already pp-number tokens,
    which are invalid tokens, requiring a diagnostic.

    One practical advantage of adding a named entity (with a value of 0)
    was to easily grep (find) appearances of this value in source code.

    0[Pp] ticks off that box. So does NULL.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Chris M. Thomasson on Sat Jul 6 23:03:38 2024
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
    On 7/6/2024 7:04 AM, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>> NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >> use the NULL macro in both C and C++ code.

    Where:

    void* x = 0;

    Should be x = 0xc0eeeeee, right?

    Sort of. In the context of the processor only the
    low-order 24-bits (6 BCD digits) indicated the null
    pointer. '0xc' was a positive sign and the following
    digit selected one of eight base-limit registers.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to bart on Sat Jul 6 23:09:24 2024
    bart <bc@freeuk.com> writes:
    On 06/07/2024 15:04, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>> NULL).

    We also used 0 as "universal" pointer value regularly without problems.

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >> use the NULL macro in both C and C++ code.


    You can ignore that requirement and just use all-bits-zero (in memory,
    not just in C source code). After all, the only thing you might want
    hardware support for is trapping a dereference of a NULL value.

    Actually, that is incorrect.

    The hardware supported an instruction to search a linked list
    for a specified key (up to 100 units[*] in length). The search
    instruction specified the head of list pointer, offset to next
    link field and a condition
    (<, <=, ==, !=, >=, >, any-bit-equal, no-bit-equal, max) and
    would search the specified list until the condition was met
    or the null pointer was read. The instruction returned the
    target node or the null pointer in an output register.

    [*] 1-to-100 bytes or 1-to-100 BCD digits.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Andrey Tarasevich on Sat Jul 6 23:04:19 2024
    Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
    On 07/06/24 7:04 AM, Scott Lurndal wrote:

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >> use the NULL macro in both C and C++ code.


    But that achieved absolutely nothing over using plain `0` in the source
    code.

    The `NULL` you used was still defined as `0` (in C++ libs) and 0 or
    `(void *) 0` (in C libs).

    Which ambiguity is yet another reason to use the NULL or nullptr
    tokens.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Richard Damon on Sat Jul 6 23:10:42 2024
    Richard Damon <richard@damon-family.org> writes:
    On 7/6/24 4:23 PM, Chris M. Thomasson wrote:
    On 7/6/2024 7:04 AM, Scott Lurndal wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

        char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0 >>>>> null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that >>>>> use
    NULL).

    We also used 0 as "universal" pointer value regularly without problems. >>>
    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee.  I
    always
    use the NULL macro in both C and C++ code.

    Where:

    void* x = 0;

    Should be x = 0xc0eeeeee, right?


    Maybe when the representation of x is examined by reinterpreting it as
    an array of character types (like unsigned char).

    FWIW, this was on a BCD architecture. Pointers were an 32-bit (8 digit)
    field with a sign digit, base-selection digit and six-digit offset.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Ben Bacarisse on Sat Jul 6 23:13:02 2024
    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>> NULL).

    We also used 0 as "universal" pointer value regularly without
    problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe >because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >> use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer
    "really" is on some hardware, 0 must work in C, including in comparisons
    with == and !=. You can have

    Yes. However, I consider that ambiguous, I prefer to be explicit and
    use NULL or nullptr. Horses for courses.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Chris M. Thomasson on Sat Jul 6 21:44:03 2024
    On 7/6/24 4:23 PM, Chris M. Thomasson wrote:
    On 7/6/2024 7:04 AM, Scott Lurndal wrote:
    ...
    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee.  I
    always
    use the NULL macro in both C and C++ code.

    Where:

    void* x = 0;

    Should be x = 0xc0eeeeee, right?

    No, 0 is a null pointer constant. The C standard requires that when a
    null pointer constant is converted to a pointer value, it must be
    converted to a null pointer of that type. The result will be that the representation of 'x' after such an assignment would be 0xc0eeeeee.

    Whether or not an integer value of 0xc0eeeeee can be converted to a
    pointer type, and what that pointer's value would be after the
    conversion is up to the implementation.

    Note that even after x acquires that representation, it's still required
    to compare equal to 0. For the purposes of the comparison, the null
    pointer constant gets converted to a null pointer of the appropriate
    type. All null pointers, regardless of representation (the C standard
    allows there to be multiple ways of representing null pointers) must
    compare equal.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Scott Lurndal on Sat Jul 6 20:06:49 2024
    scott@slp53.sl.home (Scott Lurndal) writes:

    Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

    On 07/06/24 7:04 AM, Scott Lurndal wrote:

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >>> use the NULL macro in both C and C++ code.

    But that achieved absolutely nothing over using plain `0` in the source
    code.

    The `NULL` you used was still defined as `0` (in C++ libs) and 0 or
    `(void *) 0` (in C libs).

    Which ambiguity is yet another reason to use the NULL or nullptr
    tokens.

    The definition of NULL is ambiguous and that is a reason in
    /favor/ of using NULL? Not to me it isn't.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Scott Lurndal on Sat Jul 6 20:10:50 2024
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:

    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 06.07.2024 14:54, Kaz Kylheku wrote:

    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:

    If you were creating C code today and could use a C23 compiler, would >>>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0 >>>>> null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>>> NULL).

    We also used 0 as "universal" pointer value regularly without
    problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe
    because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >>> use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer
    "really" is on some hardware, 0 must work in C, including in comparisons
    with == and !=. You can have

    Yes. However, I consider that ambiguous, [...]

    You consider something that is not ambiguous to be ambiguous? You must
    mean something different by the word ambiguous than I do.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Ben Bacarisse on Sat Jul 6 20:36:09 2024
    Ben Bacarisse <ben@bsb.me.uk> writes:

    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 06.07.2024 14:54, Kaz Kylheku wrote:

    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:

    If you were creating C code today and could use a C23 compiler, would >>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>> NULL).

    We also used 0 as "universal" pointer value regularly without
    problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe because of pre-C exposure (B and BCPL).

    Me too. If I had to guess about why, I think I would say (1) being
    used to it from the original K&R, and (2) it's philosophically
    consistent with how if(), for(), while(), and logical expressions
    work. Speaking for myself that consistency is worth a lot, and
    using NULL sticks out like a sore thumb.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to bart on Sun Jul 7 04:55:14 2024
    On Sat, 6 Jul 2024 14:51:19 +0100, bart wrote:

    Using actual zero for a pointer value is crass. This wouldn't work for example:

    char *p = 3;

    But of course this does:

    char *p = 0;

    From the C23 spec, I found this footnote in §6.6:

    A named constant or compound literal constant of integer type and
    value zero is a null pointer constant. A named constant or
    compound literal constant with a pointer type and a value null is
    a null pointer but not a null pointer constant; it may only be
    used to initialize a pointer object if its type implicitly
    converts to the target type.

    That first sentence is so important, you’d think it would be in the main
    text somewhere.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Chris M. Thomasson on Sun Jul 7 08:01:48 2024
    On Sat, 6 Jul 2024 13:28:21 -0700, Chris M. Thomasson wrote:

    void* a = 0;
    void* b = NULL;

    a == b, right?

    According to the C spec, yes.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to David Brown on Sun Jul 7 08:00:18 2024
    On Sat, 6 Jul 2024 18:57:08 +0200, David Brown wrote:

    ... and for C compilers to support a flag like gcc's "-Wzero-as-null
    -pointer-constant" warning ...

    The trouble with compiler flags is they can never be part of any language
    spec.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Chris M. Thomasson on Sun Jul 7 08:03:09 2024
    On Sat, 6 Jul 2024 13:23:30 -0700, Chris M. Thomasson wrote:

    void* x = 0;

    Should be x = 0xc0eeeeee, right?

    Only in the sense of doing an unsafe conversion, like via a union type,
    for example.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Scott Lurndal on Sun Jul 7 08:46:10 2024
    On 2024-07-06, Scott Lurndal <scott@slp53.sl.home> wrote:
    Ben Bacarisse <ben@bsb.me.uk> writes:
    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer >>"really" is on some hardware, 0 must work in C, including in comparisons >>with == and !=. You can have

    Yes. However, I consider that ambiguous, I prefer to be explicit and
    use NULL or nullptr. Horses for courses.

    The thing is that "null" is a word that means "zero".

    So it's a bit like saying

    #define tri 3

    is less ambiguous compared to just using 3.

    I get it that 0 is not exclusively a pointer constant, and syntax alone
    doesn't indicate which; indeed without type information, we don't know
    whether p == 0 is a pointer comparison, floating-point comparison or
    integer comparison. Whereas with some other kinds of expressions,
    we know more: e.g. p->memb, if correct, tells us that p is a pointer
    to a struct or union.

    If we have to use someting other than 0 to help us understand p == 0,
    maybe the circumstances of the p are not clear enough?

    What about "if (p)" and "if (!p)". If 0 is ambiguous, these should
    always be written "if (p != nullptr)" and "if (p == nullptr)".
    Otherwise p could be a number.

    (Indeed, there are coding conventions like that: always use NULL,
    and do not test pointers as if they were Booleans.)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Lawrence D'Oliveiro on Sun Jul 7 12:07:35 2024
    On 07/07/2024 10:00, Lawrence D'Oliveiro wrote:
    On Sat, 6 Jul 2024 18:57:08 +0200, David Brown wrote:

    ... and for C compilers to support a flag like gcc's "-Wzero-as-null
    -pointer-constant" warning ...

    The trouble with compiler flags is they can never be part of any language spec.


    That is both their advantage, and their disadvantage.

    Let the C standards define what the language requires when the source
    code is correct, and have everyone agree on that. Let compiler
    implementations go beyond that and give options that some might want,
    and others not want. /I/ will probably use nullptr in C23 coding, and I
    like tools to enforce my style (because I make mistakes) but I would
    certainly not want to force others to change their style based on /my/ preferences.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to Lawrence D'Oliveiro on Sun Jul 7 18:40:02 2024
    On 07/07/2024 05:55, Lawrence D'Oliveiro wrote:
    On Sat, 6 Jul 2024 14:51:19 +0100, bart wrote:

    Using actual zero for a pointer value is crass. This wouldn't work for
    example:

    char *p = 3;

    But of course this does:

    char *p = 0;

    From the C23 spec, I found this footnote in §6.6:

    A named constant or compound literal constant of integer type and
    value zero is a null pointer constant. A named constant or
    compound literal constant with a pointer type and a value null is
    a null pointer but not a null pointer constant; it may only be
    used to initialize a pointer object if its type implicitly
    converts to the target type.

    That first sentence is so important, you’d think it would be in the main text somewhere.

    It doesn't tell the full story, as you can have any arbitrary expression
    of such terms that results in a suitable value:

    char* p = width*height;

    This is valid if width/height are enums and that area calculation yields
    zero. But update values slightly and it no longer compiles.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Scott Lurndal on Sun Jul 7 19:59:25 2024
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0 >>>>> null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>>> and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use >>>>> NULL).

    We also used 0 as "universal" pointer value regularly without
    problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe >>because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always >>> use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer >>"really" is on some hardware, 0 must work in C, including in comparisons >>with == and !=. You can have

    Yes. However, I consider that ambiguous, I prefer to be explicit and
    use NULL or nullptr.

    In what sense is using 0 ambiguous? I can't see it.

    Ambiguous and explicit are not opposites, so many you did not mean to
    say that 0 is ambiguous. Its use does require the reader to know the
    role played by zero integer constant expressions in C.

    But then NULL might be defined to be 0. It /looks/ more like a pointer
    but there's lots of code that erroneously assumes that it is, presumably because of that deceptive look. (nullptr is another matter.)

    Do you always cast NULL to a pointer in those (admittedly rare) cases
    when one needs to? I think it's easier to remember to do that with 0.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Ben Bacarisse on Sun Jul 7 19:40:53 2024
    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0 >>>>>> null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>>>> and their relationship to the NULL macro, I dropped NULL like a hot >>>>>> potato, and didn't look back (except when working in code bases that use >>>>>> NULL).

    We also used 0 as "universal" pointer value regularly without >>>>>problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe >>>because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always
    use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that
    does not stop one using 0 in C source code. Whatever a null pointer >>>"really" is on some hardware, 0 must work in C, including in comparisons >>>with == and !=. You can have

    Yes. However, I consider that ambiguous, I prefer to be explicit and
    use NULL or nullptr.

    In what sense is using 0 ambiguous? I can't see it.

    the digit zero is context dependent, which makes it ambiguous.

    I.e. it can either be a null pointer or the value zero
    depending on context, which makes it ambiguous to the casual
    reader. Particularly when reading code that someone
    else has written. NULL makes the programmers intent crystal
    clear.


    Do you always cast NULL to a pointer in those (admittedly rare) cases
    when one needs to?

    I may have back in the days when I was using Version 6 C and
    AT&T C where

    $ grep NULL /work/reference/usl/uw2.01/usr/src/common/head/stddef.h
    #ifndef NULL
    #define NULL 0


    I use gcc today and it defines NULL for C as

    #define NULL ((void *)0)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Scott Lurndal on Mon Jul 8 00:42:02 2024
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 06.07.2024 14:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would >>>>>>>> you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0 >>>>>>> null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants, >>>>>>> and their relationship to the NULL macro, I dropped NULL like a hot >>>>>>> potato, and didn't look back (except when working in code bases that use
    NULL).

    We also used 0 as "universal" pointer value regularly without >>>>>>problems.

    I also like to use 0, but I'm not sure I could say exactly why. Maybe >>>>because of pre-C exposure (B and BCPL).

    Whereas I spent 6 years programming on an architecture[*] where a
    null pointer was represented in hardware by the value 0xc0eeeeee. I always
    use the NULL macro in both C and C++ code.

    I'm sure you know (but maybe some other readers might not) that that >>>>does not stop one using 0 in C source code. Whatever a null pointer >>>>"really" is on some hardware, 0 must work in C, including in comparisons >>>>with == and !=. You can have

    Yes. However, I consider that ambiguous, I prefer to be explicit and
    use NULL or nullptr.

    In what sense is using 0 ambiguous? I can't see it.

    the digit zero is context dependent, which makes it ambiguous.

    Ah. I thought we were talking about a pointer context so I thought you
    meant that using 0 in a pointer context was ambiguous. In

    char *p = 0;

    the 0 is not ambiguous (i.e. open to more than one meaning). It's open
    to being misunderstood by people who don't know C, but that true of the
    'char', the '*' and the '=' (and possibly the 'p' and the ';' too).

    I.e. it can either be a null pointer or the value zero
    depending on context, which makes it ambiguous to the casual
    reader. Particularly when reading code that someone
    else has written. NULL makes the programmers intent crystal
    clear.

    That's a rather niche readership -- one that might consider

    char *p = 0;

    unclear. Do you want such people reading your C code with a view to
    working on it?

    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone
    reading it goes "hey, what's going on here?" and ends up learning that 0
    is null pointer constant in C. They may, along the way, learn a few
    other things that they should also know before fiddling with the code.
    At the very least, they will have learnt that they don't know it all.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Ben Bacarisse on Mon Jul 8 07:19:09 2024
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone reading it goes "hey, what's going on here?" and ends up learning that 0
    is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of
    learning could just prevent a superfluous non-invention like nullptr.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kaz Kylheku on Mon Jul 8 11:08:53 2024
    On 08.07.2024 09:19, Kaz Kylheku wrote:
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone
    reading it goes "hey, what's going on here?" and ends up learning that 0
    is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of learning could just prevent a superfluous non-invention like nullptr.

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes); if it's not
    defined in a standard it gets explicitly defined individually, and
    then likely in different (non-uniform, non-standard) ways.

    To me it's more likely that because of that it had been deliberately
    added to support such desires, and less likely that the C-standards
    folks need to learn "C" and wouldn't know what 0 as a pointer value
    would mean or that it has a clear semantic in such pointer contexts.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ben Bacarisse on Mon Jul 8 12:29:23 2024
    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Janis

    [...]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Mon Jul 8 11:18:54 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 09:19, Kaz Kylheku wrote:
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone
    reading it goes "hey, what's going on here?" and ends up learning that 0 >>> is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of
    learning could just prevent a superfluous non-invention like nullptr.

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is
    useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    if it's not
    defined in a standard it gets explicitly defined individually, and
    then likely in different (non-uniform, non-standard) ways.

    To me it's more likely that because of that it had been deliberately
    added to support such desires,

    That would be a sound suggestion if "such desires" could be explained.
    Until then, I suggest it is simply harmonisation with C++. C now has
    true and false, [[...]] attributes, typeof, __has_include and no doubt
    quite a few more I've forgotten. nullptr is, until some other argument
    can be made, just another one of those.

    and less likely that the C-standards
    folks need to learn "C" and wouldn't know what 0 as a pointer value
    would mean or that it has a clear semantic in such pointer contexts.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to Kaz Kylheku on Mon Jul 8 07:18:18 2024
    On 7/8/24 3:19 AM, Kaz Kylheku wrote:
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone
    reading it goes "hey, what's going on here?" and ends up learning that 0
    is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of learning could just prevent a superfluous non-invention like nullptr.


    Remember, it was invented on the C++ side, where it has some very useful
    uses due to overloading.

    And then brought over to C to minimize the differences.

    Nothing made it manditory, so if you want to make your reader learn more
    about C, go ahead and use things that are somewhat obscure.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Keith Thompson on Mon Jul 8 14:09:35 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:
    Ben Bacarisse <ben@bsb.me.uk> writes:
    [...]
    Do you always cast NULL to a pointer in those (admittedly rare) cases >>>when one needs to?

    I may have back in the days when I was using Version 6 C and
    AT&T C where

    $ grep NULL /work/reference/usl/uw2.01/usr/src/common/head/stddef.h
    #ifndef NULL
    #define NULL 0


    I use gcc today and it defines NULL for C as

    #define NULL ((void *)0)

    Consider a variadic function that uses a null pointer to terminate the >argument list. Then I always use NULL cast to the appropriate pointer
    type.

    For example, execl() requires a final argument that should be
    `(char*)NULL`.

    On the other hand, execl() is specified by POSIX, which also happens to >require NULL to be of type void* -- and you can pretty much get away
    with using a void* null pointer where a char* null pointer is expected.

    Yes, that would be my reading.


    But casting NULL to the appropriate type (checked by reading the man
    page) requires less thought.

    Perhaps. For me, it is more rote than thought at this point.

    And it's been a couple of decades since I needed to call
    one of the exec functions directly :-)


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.

    I agree 100% with this.


    In C23, I'll use nullptr rather than NULL *if* I don't care about
    portability to pre-C23 compilers. (I use nullptr in C++.)

    I haven't made the transition to nullptr in C++ yet, too many years
    of using NULL and code bases that need to compile with older
    standards (pre C++11, until very recently) - granted one might

    #define nullptr (void *)NULL

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Ben Bacarisse on Mon Jul 8 11:03:42 2024
    On 7/7/24 19:42, Ben Bacarisse wrote:
    scott@slp53.sl.home (Scott Lurndal) writes:
    ...
    I.e. it can either be a null pointer or the value zero
    depending on context, which makes it ambiguous to the casual
    reader. Particularly when reading code that someone
    else has written. NULL makes the programmers intent crystal
    clear.

    That's a rather niche readership -- one that might consider

    char *p = 0;

    unclear. Do you want such people reading your C code with a view to
    working on it?


    The problem is not "char p=0;". If you're sure what type p has, there's
    no problem. The problem comes with code like "p=0", where "p=NULL" would
    serve to remind you that p should be a pointer, while "p=nullptr"
    guarantees a diagnostic if p is not a pointer. I have fixed bugs which
    would have been caught a lot earlier if nullptr had existed, and had
    been the only permitted kind of null pointer constant.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Mon Jul 8 17:23:23 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is
    useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Can you say more?

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ben Bacarisse on Mon Jul 8 20:07:26 2024
    On 08.07.2024 18:23, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is
    useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Can you say more?

    Frankly, no. Not more than has been already written (not only by me
    but also by others) in a couple posts of this thread. It's so clear to
    me that if it's not obvious I don't know what would help to explain
    (i.e. without going into micro-management explanations). - If yet you
    haven't experienced a necessity for an alpha pattern for the value 0,
    and since you're an experienced IT expert, I suppose it's okay for you
    as it was. - When it had been introduced in our development standards
    there was no second opinion. With C's primitive pointer concept we had
    so often issues that it was helpful to quickly find them. The 'null'
    we used was not the only convention, also suffixing pointer variables
    with '_ptr' (or camel-case as 'Ptr' in C++) helped to quickly gain
    insights, especially in (but not restricted to) code of others. Besides bug-tracking we had also other QA measures like code inspections that
    took advantage of more explicit naming supported by 'null' or '_ptr'.
    We tried to express as much as possible ("as C allows") by conventions
    and additions to a class library we were using. (Also things like the elsethread disrespectfully mentioned 'true' and 'false' literals; but
    since there was no first class boolean type as in more sophisticated
    HLL of that time this could not address all issues; but at least make
    the programmers' intention clearer - cf. false positives/negatives -
    and bugs easier to find.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Keith Thompson on Mon Jul 8 20:11:13 2024
    On 08.07.2024 00:17, Keith Thompson wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.

    Same here. Absolutely.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Keith Thompson on Mon Jul 8 22:28:04 2024
    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.


    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.
    Boolean: I use false much more often than 0.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Mon Jul 8 23:55:54 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 18:23, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is >>>> useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Can you say more?

    Frankly, no.

    OK.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Ben Bacarisse on Tue Jul 9 02:32:46 2024
    On 2024-07-08, Ben Bacarisse <ben@bsb.me.uk> wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 09:19, Kaz Kylheku wrote:
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone >>>> reading it goes "hey, what's going on here?" and ends up learning that 0 >>>> is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of
    learning could just prevent a superfluous non-invention like nullptr.

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    We could patch GCC to have a -Wnull-ptr-zero, which will give you a
    diagnostic for every occurrence of a zero valued integer expression that becomes a null pointer constant rather than an integer or floating-point
    value (and that isn't cast to pointer type).

    (If this were so hugely useful, someone woulda done it by now?)

    (Of course, it would go off on occurrences of NULL where NULL
    is defined as just zero; the diagnostic could be clever enough
    not to go off on expressions that are the expansion descendants
    of NULL, or optionally so.)

    (The option would actually be useful to someone wanting to convert
    0 to NULL or nullptr.)

    (Just like -Wold-style-cast in GNU C++ helps coders who only want
    to use static_cast and friends.)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to James Kuyper on Tue Jul 9 02:45:19 2024
    On 2024-07-08, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 7/7/24 19:42, Ben Bacarisse wrote:
    scott@slp53.sl.home (Scott Lurndal) writes:
    ...
    I.e. it can either be a null pointer or the value zero
    depending on context, which makes it ambiguous to the casual
    reader. Particularly when reading code that someone
    else has written. NULL makes the programmers intent crystal
    clear.

    That's a rather niche readership -- one that might consider

    char *p = 0;

    unclear. Do you want such people reading your C code with a view to
    working on it?


    The problem is not "char p=0;". If you're sure what type p has, there's
    no problem. The problem comes with code like "p=0", where "p=NULL" would serve to remind you that p should be a pointer, while "p=nullptr"
    guarantees a diagnostic if p is not a pointer.

    The programming world has moved away from tying syntax to concrete implementation though. For every time you worry in p = 0,
    p is floating, integer or pointer, a thousand coders somewhere
    are doing writing obj.foo(), where the type of obj can be one of
    half a dozen different things at run-time.

    p = 0 is nicely generic: "make p null, whatever it is".

    A pointer "responds" to this "method" by becoming null.

    And anyway, if the expression is p + 3 instead, what tells you then
    whether it's an integer, float or pointer. Should we have a
    ptrplus keyword for displacing pointers?

    Ancient C, or pre-C, had separate operators for floating-point,
    prefixed with a hash: #+, #-, #*, ...

    I have fixed bugs which
    would have been caught a lot earlier if nullptr had existed, and had
    been the only permitted kind of null pointer constant.

    All the ones I remember were about 0 being used as a variadic
    pointer argument, without a cast. I can't think of anywhere else
    it would be a problem.

    nullptr being the only null pointer constant would prevent that
    where the type is void * or char *, (or where pointers of all types all
    have the same representation).


    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Michael S on Tue Jul 9 02:49:49 2024
    On 2024-07-08, Michael S <already5chosen@yahoo.com> wrote:
    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.


    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.

    Never say never!

    printf("%f\n", 0); // undefined behavior.
    printf("%f\n", 0.0); // correct

    If you're #define-ing a floating-point constant that has
    no fractional part, you should put that .0 there.

    Someone's going to pass your constant as a variadic argument,
    where it doesn't convert to floating-point.

    Also:

    1/3 -> 0
    1/3.0 -> 0.33333...

    If you're #define-ing a floating point constant that has
    no fractional part, and don't include the .0, and the
    programmer uses it as a division denominator thinking that
    it's a floating-point quantity, oops!

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Michael S on Mon Jul 8 20:17:37 2024
    Michael S <already5chosen@yahoo.com> writes:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.
    Boolean: I use false much more often than 0.

    This posting has inspired me to try using (long)0.0
    whenever a null pointer constant is needed. As for
    example

    (void*){ (long)0.0 }

    as an argument to a variadic function where a pointer
    is expected.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Tarasevich@21:1/5 to Keith Thompson on Mon Jul 8 21:45:25 2024
    On 07/07/24 3:17 PM, Keith Thompson wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null character,
    0.0 when I want a floating-point zero, and false when I want a Boolean
    zero. I just like being explicit.


    Me too.

    But at the same time I realize that this is a habit forced upon my by circumstances, by necessity. C (as well as C++) at its beginning (and
    when I started to use the language) was not very well-suited for type-agnostic/DRY programming. It had a few odd features/idioms
    acknowledging the possibility, but by large both languages were
    predominantly type-aware or type-explicit. I reckon, this is actually
    what made you to "like" such explicitness. But it is pointless to talk
    about "liking" something, when one really had no choice.

    The moment C++ realized the full power of generic/template programming,
    it immediately rushed head-over-heels into type-agnostic programming
    style. It was `auto` and `decltype` initially, which then just opened
    the proverbial floodgates, triggering the avalanche of additional
    features targeted at the type-agnostic programming style. Many in C++
    world still protest it, claiming that old-style type-explicit code is
    "easier to read", but they are nothing more than overgrown kids being
    reluctant to take the training wheels off their bikes (since they make
    it "easier to ride"). There no doubt anymore than type-agnostic
    programming is the next big thing for C++.

    The same goes for C. C is not C++, of course, but with the introduction
    of `typeof` in C23 and, hopefully, better `_Generic` appearing one of
    these days, one can hope that being type-explicit is a thing of the past
    in C as well.

    So, no. While I too prefer to use `NULL` for pointers and '\0' for
    character constants, I realize that do it out of deep-seated habit, or
    for nostalgic/luddite reasons mostly. Plain undecorated `0` as a
    universal type-agnostic constant should really be my choice everywhere
    today.

    --
    Best regards,
    Andrey

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Tarasevich@21:1/5 to Andrey Tarasevich on Mon Jul 8 21:49:10 2024
    On 07/08/24 9:45 PM, Andrey Tarasevich wrote:

    So, no. While I too prefer to use `NULL` for pointers and '\0' for
    character constants, I realize that do it out of deep-seated habit, or
    for nostalgic/luddite reasons mostly. Plain undecorated `0` as a
    universal type-agnostic constant should really be my choice everywhere
    today.

    ... although, one the second thought, one can probably start a Holy War
    about what a proper type-agnostic declaration of a `double` variable
    should look like

    double d = 0;

    or

    auto d = 0.0;

    --
    Best regards,
    Andrey

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to David Brown on Tue Jul 9 06:42:30 2024
    On 06/07/2024 17:57, David Brown wrote:
    On 06/07/2024 16:39, Richard Damon wrote:
    On 7/6/24 7:49 AM, Thiago Adams wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    I am asking because I think I will keep using NULL.

    I like nullptr semantics but I don't like to introduce new element
    (nullptr) inside the code with no guarantee that the code will not
    mix both.

    In the past we also didn't have a guarantee we are not mixing 0 or NULL. >>>
    I think the best scenario for a team guideline would be a style
    warning if 0 or nullptr is used and NULL to be defined as nullptr in
    a C23 compiler.


    The (small) problem with 0 or NULL being use is that in a context
    where you THINK you are passing a pointer, but the function actually
    is taking an integer value, 0 or NULL (defined as a 0) passes the
    syntax check.

    If C23 REQURIED NULL to be defined as nullptr, then NULL would have
    been used, but as far as I know, it is still allowed to be defined as
    0 (unless you also have POSIX compatibility).

    With POSIX Compatibility, where NULL must have the type of (void*) you
    also avoid the possible error, and thus the desire to use nullptr.

    I hope that defining NULL as nullptr will become common - but I would be surprised to ever see it being required by C standards.

    The ideal would be for C libraries to define NULL as nullptr and for C compilers to support a flag like gcc's "-Wzero-as-null-pointer-constant" warning (it is currently C++ only).  Then people can easily eliminate
    any mixup between integer 0 and null pointer constants by using that
    flag and either NULL or nullptr, according to taste.  (And those who
    don't want such checks, are not required to change.)



    So, if malloc was changed to 'returns nullptr and sets errno on error',
    will you still be able to say:

    if ( p == NULL ) ...
    if ( !p ) ...

    ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Chris M. Thomasson on Tue Jul 9 08:02:42 2024
    On 09/07/2024 07:17, Chris M. Thomasson wrote:
    On 7/8/2024 10:42 PM, Richard Harnden wrote:
    On 06/07/2024 17:57, David Brown wrote:
    On 06/07/2024 16:39, Richard Damon wrote:
    On 7/6/24 7:49 AM, Thiago Adams wrote:
    If you were creating C code today and could use a C23 compiler,
    would you use nullptr instead of NULL?

    I am asking because I think I will keep using NULL.

    I like nullptr semantics but I don't like to introduce new element
    (nullptr) inside the code with no guarantee that the code will not
    mix both.

    In the past we also didn't have a guarantee we are not mixing 0 or
    NULL.

    I think the best scenario for a team guideline would be a style
    warning if 0 or nullptr is used and NULL to be defined as nullptr
    in a C23 compiler.


    The (small) problem with 0 or NULL being use is that in a context
    where you THINK you are passing a pointer, but the function actually
    is taking an integer value, 0 or NULL (defined as a 0) passes the
    syntax check.

    If C23 REQURIED NULL to be defined as nullptr, then NULL would have
    been used, but as far as I know, it is still allowed to be defined
    as 0 (unless you also have POSIX compatibility).

    With POSIX Compatibility, where NULL must have the type of (void*)
    you also avoid the possible error, and thus the desire to use nullptr.

    I hope that defining NULL as nullptr will become common - but I would
    be surprised to ever see it being required by C standards.

    The ideal would be for C libraries to define NULL as nullptr and for
    C compilers to support a flag like gcc's
    "-Wzero-as-null-pointer-constant" warning (it is currently C++ only).
    Then people can easily eliminate
    any mixup between integer 0 and null pointer constants by using that
    flag and either NULL or nullptr, according to taste.  (And those who
    don't want such checks, are not required to change.)



    So, if malloc was changed to 'returns nullptr and sets errno on
    error', will you still be able to say:

    if ( p == NULL ) ...
    if ( !p ) ...

    ?

    This of a pointer p where:

    p = 0;

    No, I mean when p = nullptr

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Kaz Kylheku on Tue Jul 9 11:00:19 2024
    On Tue, 9 Jul 2024 02:49:49 -0000 (UTC)
    Kaz Kylheku <643-408-1753@kylheku.com> wrote:

    On 2024-07-08, Michael S <already5chosen@yahoo.com> wrote:
    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when I
    want a Boolean zero. I just like being explicit.


    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.

    Never say never!

    printf("%f\n", 0); // undefined behavior.
    printf("%f\n", 0.0); // correct


    Yes, but that's extremely rare that I want constant (except string
    literal) as variable argument to printf().

    If you're #define-ing a floating-point constant that has
    no fractional part, you should put that .0 there.


    I am trying hard to avoid #define-ing floating-point constants.
    In rare cases where it is not avoidable, most often the constant does
    have fractional part. I am not sure what I would prefer when I can't
    avoid #define-ing and the constant has no fractional part. Will I write something like '#define ANSWER ((double)42)' or (42.0) ?
    It depends on the mood of the minute.

    Someone's going to pass your constant as a variadic argument,
    where it doesn't convert to floating-point.

    Also:

    1/3 -> 0
    1/3.0 -> 0.33333...

    If you're #define-ing a floating point constant that has
    no fractional part, and don't include the .0, and the
    programmer uses it as a division denominator thinking that
    it's a floating-point quantity, oops!


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Chris M. Thomasson on Tue Jul 9 10:48:48 2024
    On Mon, 8 Jul 2024 15:23:47 -0700
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    On 7/8/2024 12:28 PM, Michael S wrote:
    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when I
    want a Boolean zero. I just like being explicit.


    Pointer: I very rarely use NULL.
    Character: I never use '\0'.

    Not even something like:

    #define CLINE 128

    char x[CLINE] = { '\0' };

    ?

    ;^)


    I see nothing special about your case. {0} is the most appropriate.
    And, BTW, I never use #define for integer constants.



    Floating point: I never use 0.0.
    Boolean: I use false much more often than 0.



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Michael S on Tue Jul 9 08:21:02 2024
    On 2024-07-09, Michael S <already5chosen@yahoo.com> wrote:
    On Tue, 9 Jul 2024 02:49:49 -0000 (UTC)
    Kaz Kylheku <643-408-1753@kylheku.com> wrote:

    On 2024-07-08, Michael S <already5chosen@yahoo.com> wrote:
    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:


    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when I
    want a Boolean zero. I just like being explicit.


    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.

    Never say never!

    printf("%f\n", 0); // undefined behavior.
    printf("%f\n", 0.0); // correct


    Yes, but that's extremely rare that I want constant (except string
    literal) as variable argument to printf().

    Under the paradigm of "I write code only for myself", almost
    anything is justifiable.

    The "I want" stuff goes out the window as soon as your source code is
    consumed by other programmers. (Interfaced with, patched, taken
    over by ...). Anything you define could be used in ways you wouldn't
    do yourself.


    // #define GRAV 9.81
    #define GRAV 3

    ...

    printf("configured with\n");
    ...
    printf("GRAV=%g\n", GRAV);


    If you're #define-ing a floating-point constant that has
    no fractional part, you should put that .0 there.


    I am trying hard to avoid #define-ing floating-point constants.
    In rare cases where it is not avoidable, most often the constant does
    have fractional part. I am not sure what I would prefer when I can't
    avoid #define-ing and the constant has no fractional part. Will I write something like '#define ANSWER ((double)42)' or (42.0) ?
    It depends on the mood of the minute.

    You don't need parentheses around 42.0, because the floating point
    dot has a higher precedence than any operator. :-)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Chris M. Thomasson on Tue Jul 9 11:14:41 2024
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:


    p = nullptr;

    (p having been declared void *)

    (0 == p == nullptr == NULL == 0) == true ?

    Am I missing something here? If so, here is a preemptive: Shit!

    You are missing that 0 == p == nullptr == NULL == 0 does not mean what
    you want! It means

    (((0 == p) == nullptr) == NULL) == 0

    and that is a constraint violation.

    Why? Well 0 == p has value 1 and is of type int and equality
    comparisons between int and nullptr_t values (of which there is only
    one) are not permitted. Catching this sort of thing is one of the
    benefits of nullptr and its associated type nullptr_t. It means that
    while

    #define nullptr ((void *)0)

    can help to get C23 code to compile with a pre-C23 compiler, it might
    result in some C23 constraint violations going undetected.

    Anyway, that aside, I know what you meant. To clarify, all of the
    following have the value 1:

    0 == p
    p == nullptr
    nullptr == NULL
    NULL == 0
    0 == nullptr
    !p

    Note that 0 == nullptr /is/ allowed even though 0 has type int. That is because 0 is also a null pointer constant, and the rules for == and != specifically allow it.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Kaz Kylheku on Tue Jul 9 10:21:56 2024
    Kaz Kylheku <643-408-1753@kylheku.com> writes:

    On 2024-07-08, Ben Bacarisse <ben@bsb.me.uk> wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 09:19, Kaz Kylheku wrote:
    On 2024-07-07, Ben Bacarisse <ben@bsb.me.uk> wrote:
    I find myself completely out of step with many posters here about
    "explicit code" should look like. I think

    char *p = 0;

    is explicit enough and, in fact, I consider it a plus point if someone >>>>> reading it goes "hey, what's going on here?" and ends up learning that 0 >>>>> is null pointer constant in C.

    And if that person is on the C or C++ langauge committee, that bit of
    learning could just prevent a superfluous non-invention like nullptr.

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is
    useful. I can see management wanting one to find all uses of a null
    pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    We could patch GCC to have a -Wnull-ptr-zero, which will give you a diagnostic for every occurrence of a zero valued integer expression that becomes a null pointer constant rather than an integer or floating-point value (and that isn't cast to pointer type).

    Sure.

    I once tried to persuade the compiler team where I worked to write a
    "tool box" for diagnostics that would have a meta-language in which
    users could describe the conditions that wanted to be diagnosed. The
    idea was half-baked so it never went anywhere.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Michael S on Tue Jul 9 03:57:49 2024
    Michael S <already5chosen@yahoo.com> writes:

    On Tue, 9 Jul 2024 02:49:49 -0000 (UTC)
    Kaz Kylheku <643-408-1753@kylheku.com> wrote:

    On 2024-07-08, Michael S <already5chosen@yahoo.com> wrote:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when I
    want a Boolean zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.
    Floating point: I never use 0.0.

    Never say never!

    printf("%f\n", 0); // undefined behavior.
    printf("%f\n", 0.0); // correct

    Yes, but that's extremely rare that I want constant (except string
    literal) as variable argument to printf().

    If you're #define-ing a floating-point constant that has
    no fractional part, you should put that .0 there.

    I am trying hard to avoid #define-ing floating-point constants.
    In rare cases where it is not avoidable, most often the constant does
    have fractional part. I am not sure what I would prefer when I can't
    avoid #define-ing and the constant has no fractional part. Will I write something like '#define ANSWER ((double)42)' or (42.0) ?
    It depends on the mood of the minute.

    Normally I would leave off the final 0 and just write 42.

    Alternatively, a floating-point 42 can be written 42e0,
    which stands out a little more than just using a trailing
    dot.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Michael S on Tue Jul 9 04:32:50 2024
    Michael S <already5chosen@yahoo.com> writes:

    On Mon, 8 Jul 2024 15:23:47 -0700
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    On 7/8/2024 12:28 PM, Michael S wrote:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when I
    want a Boolean zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.

    Not even something like:

    #define CLINE 128

    char x[CLINE] = { '\0' };

    ?

    ;^)

    I see nothing special about your case. {0} is the most appropriate.

    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    And, BTW, I never use #define for integer constants.

    What do you do if you need to define a compile-time constant
    whose value is outside the range of signed int? With the
    understanding that the context is C as it is now, and not
    C++ or some imagined other language.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael S@21:1/5 to Tim Rentsch on Tue Jul 9 15:50:14 2024
    On Tue, 09 Jul 2024 04:32:50 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Mon, 8 Jul 2024 15:23:47 -0700
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    On 7/8/2024 12:28 PM, Michael S wrote:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when
    I want a Boolean zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.

    Not even something like:

    #define CLINE 128

    char x[CLINE] = { '\0' };

    ?

    ;^)

    I see nothing special about your case. {0} is the most appropriate.


    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    And, BTW, I never use #define for integer constants.

    What do you do if you need to define a compile-time constant
    whose value is outside the range of signed int? With the
    understanding that the context is C as it is now, and not
    C++ or some imagined other language.

    In comment above "integer constant" meant "within the range of signed
    int". But let's accept more general meaning. Then, when it happens, I
    have a problem and forced to flex my principles :(
    Luckily, it's pretty rare. I mean, it's pretty rare that the constant
    is both outside the range of signed int and I really really have to
    have it as compile-time constant. More often big numbers like these are
    used in arithmetic/logic, so 'const wide_type' or 'static const
    wide_type' is practically as good as a "real" compile-time constant
    despite being "less constant" in theory.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Thiago Adams on Tue Jul 9 07:52:17 2024
    Thiago Adams <thiago.adams@gmail.com> writes:

    On 09/07/2024 08:32, Tim Rentsch wrote:

    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    I like to pretend

    '\0' is not int
    2 > 1 is not int
    etc

    I know it is int, but I think this needs a redesign in C.

    I strongly encourage you not to do that. Based on past
    experience most of your ideas for improvements make
    things worse rather than better.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Michael S on Tue Jul 9 07:50:59 2024
    Michael S <already5chosen@yahoo.com> writes:

    On Tue, 09 Jul 2024 04:32:50 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Mon, 8 Jul 2024 15:23:47 -0700
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    On 7/8/2024 12:28 PM, Michael S wrote:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when
    I want a Boolean zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.

    Not even something like:

    #define CLINE 128

    char x[CLINE] = { '\0' };

    ?

    ;^)

    I see nothing special about your case. {0} is the most appropriate.

    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    And, BTW, I never use #define for integer constants.

    What do you do if you need to define a compile-time constant
    whose value is outside the range of signed int? With the
    understanding that the context is C as it is now, and not
    C++ or some imagined other language.

    In comment above "integer constant" meant "within the range of signed
    int". But let's accept more general meaning. Then, when it happens, I
    have a problem and forced to flex my principles :(
    Luckily, it's pretty rare. I mean, it's pretty rare that the constant
    is both outside the range of signed int and I really really have to
    have it as compile-time constant.

    I agree it's not common. I was just wondering what you would
    do if it came up (and as it happens it did come up for me
    recently, and I used a #define rather than trying to find an
    alternative).

    More often big numbers like these are
    used in arithmetic/logic, so 'const wide_type' or 'static const
    wide_type' is practically as good as a "real" compile-time constant
    despite being "less constant" in theory.

    I routinely use initialized ordinary variables rather than
    other methods, when the variables work. Incidentally, IME
    the results are better with automatic variables rather than
    static. For arrays or structs, static might be better, but
    for simple scalar values I normally use ordinary automatics
    rather than statics.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Michael S on Tue Jul 9 18:19:20 2024
    On 09/07/2024 14:50, Michael S wrote:
    On Tue, 09 Jul 2024 04:32:50 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Mon, 8 Jul 2024 15:23:47 -0700
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> wrote:

    On 7/8/2024 12:28 PM, Michael S wrote:

    On Sun, 07 Jul 2024 15:17:34 -0700
    Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

    I just about always use NULL, not 0, when I want a null pointer
    constant. Similarly, I use '\0', not 0, when I want a null
    character, 0.0 when I want a floating-point zero, and false when
    I want a Boolean zero. I just like being explicit.

    Pointer: I very rarely use NULL.
    Character: I never use '\0'.

    Not even something like:

    #define CLINE 128

    char x[CLINE] = { '\0' };

    ?

    ;^)

    I see nothing special about your case. {0} is the most appropriate.


    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    And, BTW, I never use #define for integer constants.

    What do you do if you need to define a compile-time constant
    whose value is outside the range of signed int? With the
    understanding that the context is C as it is now, and not
    C++ or some imagined other language.

    In comment above "integer constant" meant "within the range of signed
    int". But let's accept more general meaning. Then, when it happens, I
    have a problem and forced to flex my principles :(
    Luckily, it's pretty rare. I mean, it's pretty rare that the constant
    is both outside the range of signed int and I really really have to
    have it as compile-time constant. More often big numbers like these are
    used in arithmetic/logic, so 'const wide_type' or 'static const
    wide_type' is practically as good as a "real" compile-time constant
    despite being "less constant" in theory.


    static const of the appropriate type should be as good as a define'd
    value in almost any circumstance (assuming, of course, an optimising
    compiler).

    There are circumstances where you can use an enumeration constant as a
    named integer constant, but where a static const int value cannot be
    used, such as the size of statically allocated arrays. But you are very unlikely to need such a large value to be an integer constant, rather
    than just a value that the compiler sees as a compile-time constant for optimisation purposes.

    (And C23 helpfully allows enum values that are of larger integer types.
    And also "constexpr" declarations.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Thiago Adams on Tue Jul 9 14:22:15 2024
    Thiago Adams <thiago.adams@gmail.com> writes:

    On 09/07/2024 11:52, Tim Rentsch wrote:

    Thiago Adams <thiago.adams@gmail.com> writes:

    On 09/07/2024 08:32, Tim Rentsch wrote:

    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    I like to pretend

    '\0' is not int
    2 > 1 is not int
    etc

    I know it is int, but I think this needs a redesign in C.

    I strongly encourage you not to do that. Based on past
    experience most of your ideas for improvements make
    things worse rather than better.

    It is only for static analysis.

    For instance:


    enum E {Z = 0};

    int main()
    {
    int * p;
    p = '\0';
    p = false;
    p = Z;
    }

    clang has 3 warnings for this code.

    https://godbolt.org/z/56fn5PT4h

    Especially for p = Z and p = '\0' we have value 0 of type int, but the compiler is not blind for the other characteristics.

    You could give a master class in missing the point.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Thiago Adams on Tue Jul 9 22:25:34 2024
    On 2024-07-09, Thiago Adams <thiago.adams@gmail.com> wrote:
    On 09/07/2024 08:32, Tim Rentsch wrote:
    Any use of '\0' almost always strikes me as an affectation. It's
    like people want to somehow pretend that it's not the same as
    just 0.

    I like to pretend

    '\0' is not int

    In C++ it isn't.

    void foo(int);
    void foo(char);

    foo(0); // takes int overload
    foo('\0'); // takes char overload

    I don't like to think '\0' is null pointer.

    I don't like that 1 - 1 is a null pointer. It's not a good design.

    Nobody other than C humorists needs any zero-valued integer expression whatsoever to be a null pointer constant.

    How it should work is that only the token 0 is a null pointer constant.
    Not 0L (ideally, not even 00 or 0x0, only the decimal token).

    All zero-valued constant expressions of integer type should not be
    null pointer constants, but ordinary expressions whch require
    a cast to be converted to pointer type, and denote an address
    associated with zero that may be different from the null pointer.


    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Chris M. Thomasson on Wed Jul 10 14:27:45 2024
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

    On 7/9/2024 1:24 PM, Chris M. Thomasson wrote:
    On 7/9/2024 3:14 AM, Ben Bacarisse wrote:
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:


    p = nullptr;

    (p having been declared void *)

    (0 == p == nullptr == NULL == 0) == true ?

    Am I missing something here? If so, here is a preemptive: Shit!

    You are missing that 0 == p == nullptr == NULL == 0 does not mean what
    you want! It means

    (((0 == p) == nullptr) == NULL) == 0

    and that is a constraint violation.

    Why? Well 0 == p has value 1 and is of type int and equality
    comparisons between int and nullptr_t values (of which there is only
    one) are not permitted. Catching this sort of thing is one of the
    benefits of nullptr and its associated type nullptr_t. It means that
    while

    #define nullptr ((void *)0)

    can help to get C23 code to compile with a pre-C23 compiler, it might
    result in some C23 constraint violations going undetected.

    Anyway, that aside, I know what you meant. To clarify, all of the
    following have the value 1:

    0 == p
    p == nullptr
    nullptr == NULL
    NULL == 0
    0 == nullptr
    !p

    Note that 0 == nullptr /is/ allowed even though 0 has type int. That is >>> because 0 is also a null pointer constant, and the rules for == and !=
    specifically allow it.

    It was a bit of pseudo code.

    It looked like C!

    Here is a program:
    __________________________
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
    void* p = 0;
    if ((p == NULL) && (! p))
    {
    printf("Good!\n");
    }
    else
    {
    printf("Strange? Humm...\n");
    }
    return 0;
    }
    __________________________
    Good shall be printed even with the following condition right?
    __________________________
    if ((p == NULL) && (! p) && (p == nullptr))
    {
    printf("Good!\n");
    }
    __________________________
    Any better Ben?

    To be more precise, printf shall be called if p is 0, NULL or
    nullptr... They are all the same, in a sense, right?

    In a sense, yes. If you want to know the senses in which they are not
    all the same, ask some more (or read the C23 draft PDF).

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Keith Thompson on Wed Jul 10 07:36:14 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Hmm. I like the idea of a type-agnostic way to express a "zero"
    value, [but] C's use of 0 for all scalar types strikes me more as
    an historical accident than a design feature.

    I don't think it was an accident at all. It was chosen to be
    consistent with how if(), while(), !, ?:, and so forth, all act.
    There is a very consistent design philosophy there. Sometimes
    people who come from a strong Pascal background don't like it,
    but personally I find the C model easier and more convenient to
    work with than the Pascal model.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Keith Thompson on Wed Jul 10 07:51:58 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    This posting has inspired me to try using (long)0.0
    whenever a null pointer constant is needed. As for
    example

    (void*){ (long)0.0 }

    as an argument to a variadic function where a pointer
    is expected.

    But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.

    Surely not. Furthermore the form I showed has a point,
    whereas this example is roughly the equivalent of a
    first grade knock-knock joke.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Chris M. Thomasson on Wed Jul 10 11:09:41 2024
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
    ...
    To be more precise, printf shall be called if p is 0, NULL or
    nullptr... They are all the same, in a sense, right?

    0 and nullptr are null pointer constants. NULL is required to expand
    into a null pointer constant, but it's not required to expand into
    either 0 or nullptr; it could expand into '\0' or 0ULL or ('a' - 'a'),
    among an infinite variety of other possibilities. 0 and (void*)0 are the
    two most likely and common choices.

    Whenever they occur in a pointer context, null pointer constants get
    implicitly converted to the corresponding pointer type, and the result
    of that conversion is a null pointer of that type. All null pointers are required to compare equal. In that sense, 0, NULL and nullptr are all equivalent.

    However, 0 can be used wherever an integer value is required. while
    nullptr cannot, which is one of the key reasons for the existence of
    nullptr. NULL can expand into an integer constant expression with a
    value of 0, but it can also expand into such an expression, converted to
    void*. If an implementation chooses the first option, NULL can be used
    wherever an integer is allowed. If it chooses the second option, NULL
    can only be used where a pointer is allowed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ben Bacarisse on Wed Jul 10 17:28:54 2024
    On 09.07.2024 00:55, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 18:23, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing
    occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is >>>>> useful. I can see management wanting one to find all uses of a null >>>>> pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Can you say more?

    Frankly, no. [...]

    OK.

    So the text you snipped from my reply did not trigger any insight?

    Another, last try...
    Compare it to 'enum' constants. When I code or debug I want to track
    (search and find) them by name not by integer number.
    Similar with the 'enum' bool type we introduced (when there was not
    yet a bool type existing in C or C++) with literal constants 'true'
    and 'false'. (Only two values, but still as important.)
    Similar with the dedicated pointer value 0 (these days we used the
    literal 'null'). (Only one value, still useful for tracking eq/ne
    comparisons and initializations.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Keith Thompson on Wed Jul 10 18:50:00 2024
    On 7/10/24 17:23, Keith Thompson wrote:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    This posting has inspired me to try using (long)0.0
    whenever a null pointer constant is needed. As for
    example

    (void*){ (long)0.0 }

    as an argument to a variadic function where a pointer
    is expected.

    But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.

    Surely not. Furthermore the form I showed has a point,
    whereas this example is roughly the equivalent of a
    first grade knock-knock joke.

    I was of course joking. I assumed you were as well.

    What is the point of (void*){ (long)0.0 }? I don't believe it's a null pointer constant even in C23.

    I think you're right about that.

    "An integer constant expression132) ... shall only have operands that
    are ... compound literal constants of arithmetic type that are the
    immediate operands of casts. ... Cast operators in an integer constant expression shall only convert arithmetic types to integer types, ...",
    so (long)0.0 is permitted."

    While (void*) looks like a cast, in this context it is a compound
    literal of pointer type, which is not allowed. If he had written

    (void*)(long)0.0

    that would not have been a problem.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Thu Jul 11 00:25:42 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 09.07.2024 00:55, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 18:23, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 08.07.2024 12:18, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    What's superfluous to one is useful for others (e.g. for grep'ing >>>>>>> occurrences of a null-pointer value in source codes);

    This is been suggested twice now but I'm struggling to see why that is >>>>>> useful. I can see management wanting one to find all uses of a null >>>>>> pointer constant to check that they have all been replaced by the
    "safer" nullptr, but what's the value in searching for nullptr?

    Bug-tracking.

    Can you say more?

    Frankly, no. [...]

    OK.

    So the text you snipped from my reply did not trigger any insight?

    I didn't read it. You said you could not say more so I assumed what
    you'd written was not saying more but something else like repeating what
    you'd already said.

    Another, last try...
    Compare it to 'enum' constants. When I code or debug I want to track
    (search and find) them by name not by integer number.
    Similar with the 'enum' bool type we introduced (when there was not
    yet a bool type existing in C or C++) with literal constants 'true'
    and 'false'. (Only two values, but still as important.)
    Similar with the dedicated pointer value 0 (these days we used the
    literal 'null'). (Only one value, still useful for tracking eq/ne
    comparisons and initializations.)

    Yes, you've said that before. You want to search for nullptr. I can't
    think of how that might help find a real bug, if that's what you mean by bug-tracking.

    I was hoping for a story... "Once I had this bug where... and if I'd
    been using nullptr I'd have found it a day earlier" kind of thing. I'd
    found a lot of bugs over the years, but I don't recall any that would
    have been easier to find had I been able to search for nullptr.

    I was looking for real-world insight here. Obviously one could make up
    a bug where p = nullptr; was written where, say, p = null - ptr; was
    intended, but that's not what I mean.

    Without such an example, your argument seems to be overly generic.
    Would you welcome the introduction of the keyword unity -- with the
    value 1 and type int -- into C because one could then search for it?

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Chris M. Thomasson on Thu Jul 11 02:12:57 2024
    "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

    On 7/9/2024 2:21 AM, Ben Bacarisse wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:

    On 2024-07-08, Ben Bacarisse <ben@bsb.me.uk> wrote:
    [...]
    We could patch GCC to have a -Wnull-ptr-zero, which will give you a
    diagnostic for every occurrence of a zero valued integer expression that >>> becomes a null pointer constant rather than an integer or floating-point >>> value (and that isn't cast to pointer type).
    Sure.
    I once tried to persuade the compiler team where I worked to write a
    "tool box" for diagnostics that would have a meta-language in which
    users could describe the conditions that wanted to be diagnosed. The
    idea was half-baked so it never went anywhere.

    No funding?

    No. As I said the idea was half-baked. I could not pin it down and
    nether could anyone else. Without a clear specification, it could not
    go forward.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Andrey Tarasevich on Thu Jul 11 02:42:14 2024
    On Mon, 8 Jul 2024 21:49:10 -0700, Andrey Tarasevich wrote:

    ... although, one the second thought, one can probably start a Holy War
    about what a proper type-agnostic declaration of a `double` variable
    should look like

    double d = 0;

    or

    auto d = 0.0;

    How about

    integer, parameter :: useprec = kind(0.0d0)
    real(kind = useprec) :: altitude, next_altitude, next_velocity, fuel_rate, elapsed

    Not quite full generics, but useful nonetheless.

    (From a program I posted on comp.lang.fortran a few weeks ago.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Janis Papanagnou on Thu Jul 11 02:38:30 2024
    On Mon, 8 Jul 2024 11:08:53 +0200, Janis Papanagnou wrote:

    To me it's more likely that because of that it had been deliberately
    added to support such desires, and less likely that the C-standards
    folks need to learn "C" and wouldn't know what 0 as a pointer value
    would mean or that it has a clear semantic in such pointer contexts.

    Back in the 1980s: “I like C because it’s not Pascal.”

    And now: yet another Pascal feature added to C.

    Of course, we called it “nil” in Pascal. Which is a name that comes from Lisp.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ben Bacarisse on Fri Jul 12 14:08:38 2024
    On 11.07.2024 01:25, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    Compare it to 'enum' constants. When I code or debug I want to track
    (search and find) them by name not by integer number.
    Similar with the 'enum' bool type we introduced (when there was not
    yet a bool type existing in C or C++) with literal constants 'true'
    and 'false'. (Only two values, but still as important.)
    Similar with the dedicated pointer value 0 (these days we used the
    literal 'null'). (Only one value, still useful for tracking eq/ne
    comparisons and initializations.)

    Yes, you've said that before. You want to search for nullptr. I can't
    think of how that might help find a real bug, if that's what you mean by bug-tracking.

    I was hoping for a story... "Once I had this bug where... and if I'd
    been using nullptr I'd have found it a day earlier" kind of thing. I'd
    found a lot of bugs over the years, but I don't recall any that would
    have been easier to find had I been able to search for nullptr.

    I was looking for real-world insight here. Obviously one could make up
    a bug where p = nullptr; was written where, say, p = null - ptr; was intended, but that's not what I mean.

    Without such an example, your argument seems to be overly generic.

    That's why I had problems to "explain" the reasons to you; because
    it's so universal a property, so obvious (as I said), that I don't
    know what else I could say. (Likewise with "real-word examples".)
    What example could I give that explains that if you're looking for
    specific dedicated semantical values it's easier to look them up
    by [semantical] name than by a [ambiguous] number. Yes this speeds
    up detection of errors when doing code inspections (for bugs or as
    QA measure), and yes, this was helpful for program development and
    bug detection in [my professional and private] practice.

    Would you welcome the introduction of the keyword unity -- with the
    value 1 and type int -- into C because one could then search for it?

    No. (Please don't start to be ridiculous. - Or did you really miss
    the point? - No offense intended.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Lawrence D'Oliveiro on Fri Jul 12 14:11:28 2024
    On 11.07.2024 04:38, Lawrence D'Oliveiro wrote:
    On Mon, 8 Jul 2024 11:08:53 +0200, Janis Papanagnou wrote:

    To me it's more likely that because of that it had been deliberately
    added to support such desires, and less likely that the C-standards
    folks need to learn "C" and wouldn't know what 0 as a pointer value
    would mean or that it has a clear semantic in such pointer contexts.

    Back in the 1980s: “I like C because it’s not Pascal.”

    And now: yet another Pascal feature added to C.

    Of course, we called it “nil” in Pascal. Which is a name that comes from Lisp.

    You're replying to (part of) my post, so I wonder what do you want
    to say (or allege) here?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Kaz Kylheku on Fri Jul 12 14:19:19 2024
    On 06/07/2024 13:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use NULL).


    I don't understand why you wouldn't use NULL.

    If it's a pointer: NULL
    If it's an integer: 0
    If it's a double: 0.0
    If it's a char: '\0'

    Don't you use '\n'? Surely nobody would say 0x0a?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Richard Harnden on Fri Jul 12 21:52:47 2024
    On 2024-07-12, Richard Harnden <richard.nospam@gmail.invalid> wrote:
    On 06/07/2024 13:54, Kaz Kylheku wrote:
    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:
    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use
    NULL).


    I don't understand why you wouldn't use NULL.

    If it's a pointer: NULL
    If it's an integer: 0
    If it's a double: 0.0
    If it's a char: '\0'

    Don't you use '\n'? Surely nobody would say 0x0a?

    But, see, nobody in their right mind would say '\012` for that. '\0'
    an octal escape sequence like '\012', not a role-based character
    abstraction like '\n'. There is no null character abstraction because
    the null character is the concrete zero code.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kaz Kylheku on Fri Jul 12 22:27:20 2024
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-07-12, Richard Harnden <richard.nospam@gmail.invalid> wrote:


    Don't you use '\n'? Surely nobody would say 0x0a?

    But, see, nobody in their right mind would say '\012` for that. '\0'
    an octal escape sequence like '\012', not a role-based character
    abstraction like '\n'.

    Actually, it's entirely likely that a programmer using C in 1978
    would have used \012 for newline - it was the custom to use octal
    on the PDP-11. Consider the od(1) utility, for example.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Sat Jul 13 00:59:19 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 11.07.2024 01:25, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    Compare it to 'enum' constants. When I code or debug I want to track
    (search and find) them by name not by integer number.
    Similar with the 'enum' bool type we introduced (when there was not
    yet a bool type existing in C or C++) with literal constants 'true'
    and 'false'. (Only two values, but still as important.)
    Similar with the dedicated pointer value 0 (these days we used the
    literal 'null'). (Only one value, still useful for tracking eq/ne
    comparisons and initializations.)

    Yes, you've said that before. You want to search for nullptr. I can't
    think of how that might help find a real bug, if that's what you mean by
    bug-tracking.

    I was hoping for a story... "Once I had this bug where... and if I'd
    been using nullptr I'd have found it a day earlier" kind of thing. I'd
    found a lot of bugs over the years, but I don't recall any that would
    have been easier to find had I been able to search for nullptr.

    I was looking for real-world insight here. Obviously one could make up
    a bug where p = nullptr; was written where, say, p = null - ptr; was
    intended, but that's not what I mean.

    Without such an example, your argument seems to be overly generic.

    That's why I had problems to "explain" the reasons to you; because
    it's so universal a property, so obvious (as I said), that I don't
    know what else I could say.

    Yes, that's been the clear for a while now. That's why, when you said
    you could not say more, I was happy to leave it at that (my "ok").

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kaz Kylheku on Sat Jul 13 00:10:44 2024
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-07-12, Scott Lurndal <scott@slp53.sl.home> wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-07-12, Richard Harnden <richard.nospam@gmail.invalid> wrote:


    Don't you use '\n'? Surely nobody would say 0x0a?

    But, see, nobody in their right mind would say '\012` for that. '\0'
    an octal escape sequence like '\012', not a role-based character >>>abstraction like '\n'.

    Because '\012' is a character. 012 is an int. Using the former
    ensures that any overflow will be detected at compile time and make
    it clear to any future reader that the author intended it to be a
    character, not an integer.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Scott Lurndal on Fri Jul 12 23:28:49 2024
    On 2024-07-12, Scott Lurndal <scott@slp53.sl.home> wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-07-12, Richard Harnden <richard.nospam@gmail.invalid> wrote:


    Don't you use '\n'? Surely nobody would say 0x0a?

    But, see, nobody in their right mind would say '\012` for that. '\0'
    an octal escape sequence like '\012', not a role-based character >>abstraction like '\n'.

    Actually, it's entirely likely that a programmer using C in 1978
    would have used \012 for newline - it was the custom to use octal
    on the PDP-11. Consider the od(1) utility, for example.

    But why would they use '\012', if 012 was available. The quotes
    and backslash doubles the character count and create visual clutter.

    If I want the number 10 of type int, why would I switch into
    a character quote inside of which I have to escape back to
    a numeric specification.

    In C++ it makes sense, because we get the char type, which can
    be important: foo('\012') -> pick the foo(char) overload, not
    the foo(int).

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Scott Lurndal on Fri Jul 12 20:28:35 2024
    On 7/12/24 20:10, Scott Lurndal wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-07-12, Scott Lurndal <scott@slp53.sl.home> wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    ...
    But, see, nobody in their right mind would say '\012` for that. '\0'
    an octal escape sequence like '\012', not a role-based character
    abstraction like '\n'.

    Because '\012' is a character. 012 is an int. Using the former
    ensures that any overflow will be detected at compile time and


    No, it does not. In C "An integer character constant has type int.". (6.4.4.4p11), the same type as 012. A compiler could warn you about such problems, but it's not required to, and a conforming compiler is not
    allowed to reject code on that basis.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ben Bacarisse on Sat Jul 13 04:01:12 2024
    On 13.07.2024 01:59, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 11.07.2024 01:25, Ben Bacarisse wrote:
    [...]
    Without such an example, your argument seems to be overly generic.

    That's why I had problems to "explain" the reasons to you; because
    it's so universal a property, so obvious (as I said), that I don't
    know what else I could say.

    Yes, that's been the clear for a while now. That's why, when you said
    you could not say more, I was happy to leave it at that (my "ok").

    You again strip the post where my try for an explanation follows:

    What example could I give that explains that if you're looking for
    specific dedicated semantical values it's easier to look them up
    by [semantical] name than by a [ambiguous] number.

    Are those semantical names so meaningless to you?

    Let's take the 'bool' sample; do you find it more helpful to look
    for numerical falues in the code than to look for standard literals
    like 'true' and 'false'? (It's not much different concerning 'NULL'.)

    (But okay, given your last response patterns you seem to not be
    interested.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Sat Jul 13 04:18:06 2024
    On 12.07.2024 14:08, Janis Papanagnou wrote:
    On 11.07.2024 01:25, Ben Bacarisse wrote:
    [...]
    Would you welcome the introduction of the keyword unity -- with the
    value 1 and type int -- into C because one could then search for it?

    No. [...]

    One addition here; you've been asking for a [general available]
    literal name for integer constants. Which is of course nonsense
    because we have no "specific dedicated semantical values" (as I
    wrote) and which is different from 'null', 'true', or 'false',
    which all are such dedicated values.

    But for specific applications it may make sense to define (for
    specific values) 'int' or 'float' literals. I've seen examples
    of software doing formal differentiation in Algol 68 and Simula.
    Despite the approach of both software versions were completely
    different, both code designers defined dedicated objects like
    'zero' and 'one', because being neutral elements these objects
    serve a special purpose in the software architecture of their
    formal differentiation algorithm. 'pi' may be another example.

    So even if your statement above had obviously a different more
    ludicrous intention [concerning a general availability of such
    'int' literals] there's specific applications where it's useful
    (or even necessary).

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Richard Harnden on Sat Jul 13 17:21:56 2024
    Richard Harnden <richard.nospam@gmail.invalid> writes:

    On 06/07/2024 13:54, Kaz Kylheku wrote:

    On 2024-07-06, Thiago Adams <thiago.adams@gmail.com> wrote:

    If you were creating C code today and could use a C23 compiler, would
    you use nullptr instead of NULL?

    In greenfield projects under my dictatorship, I use 0, as in:

    char *p = 0;

    I was still 20 something when I (easily) wrapped my head around the 0
    null pointer constant, and have not had any problems with it.
    Once I learned the standard-defined truth about null pointer constants,
    and their relationship to the NULL macro, I dropped NULL like a hot
    potato, and didn't look back (except when working in code bases that use
    NULL).

    I don't understand why you wouldn't use NULL.

    The arguments I have heard for using NULL sound a lot like
    the reason given for climbing Mount Everest. (Incidentally
    the person who said that died trying to climb the mountain.)

    If it's a pointer: NULL

    In most cases I would use 0, converted to an appropriate
    pointer type using a compound literal if necessary.

    If it's an integer: 0

    Yes in almost all cases.

    If it's a double: 0.0

    In most cases where an integral value is needed for a
    floating-point type I would use an integer. Sometimes
    a judicious 0. or 1. is needed to force conversion.

    If it's a char: '\0'

    The integer constant '\0' reminds me of the short poem
    about a purple cow.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Janis Papanagnou on Mon Jul 15 00:00:18 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 13.07.2024 01:59, Ben Bacarisse wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    On 11.07.2024 01:25, Ben Bacarisse wrote:
    [...]
    Without such an example, your argument seems to be overly generic.

    That's why I had problems to "explain" the reasons to you; because
    it's so universal a property, so obvious (as I said), that I don't
    know what else I could say.

    Yes, that's been the clear for a while now. That's why, when you said
    you could not say more, I was happy to leave it at that (my "ok").

    You again strip the post where my try for an explanation follows:

    Of course; I have nothing to say about your explanation. I understood
    it from the very first time you posted it (although I suppose I might be mistaken about that). Nothing about it is in dispute. Should I have
    kept it and ignored it?

    What example could I give that explains that if you're looking for
    specific dedicated semantical values it's easier to look them up
    by [semantical] name than by a [ambiguous] number.

    Are those semantical names so meaningless to you?

    No, I get it.

    Let's take the 'bool' sample; do you find it more helpful to look
    for numerical falues in the code than to look for standard literals
    like 'true' and 'false'? (It's not much different concerning 'NULL'.)

    I have no recollection of an occasion when searching for true or false
    has ever helped me to find a bug. If you do, please recount the story.
    That's the sort of thing that has been missing (for me).

    (But okay, given your last response patterns you seem to not be
    interested.)

    I have always been interested in hearing more about your experiences
    about what you called "bug-tracking". That's why I asked "can you say
    more?". And when you said "no" I thought that would be the end of it.

    (By the way, I still don't know what you mean by bug-tracking. I've
    assumed you mean tracking as in tracking down, i.e. finding and fixing
    bugs rather than the more usual meaning of logging and recording details
    of known bugs.)

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Richard Harnden on Mon Jul 15 22:51:25 2024
    On Fri, 12 Jul 2024 14:19:19 +0100, Richard Harnden wrote:

    Don't you use '\n'? Surely nobody would say 0x0a?

    Why not full symbolic Unicode names, à la Python:

    "\n" == "\N{LINE FEED}"



    True

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Lawrence D'Oliveiro on Mon Jul 15 19:49:08 2024
    On 7/15/24 18:51, Lawrence D'Oliveiro wrote:
    On Fri, 12 Jul 2024 14:19:19 +0100, Richard Harnden wrote:

    Don't you use '\n'? Surely nobody would say 0x0a?

    Why not full symbolic Unicode names, à la Python:

    "\n" == "\N{LINE FEED}"



    True

    Keep in mind that, in text mode, the <stdio.h> library routines use '\n'
    in memory to represent whatever platform-specific method is used in
    files to indicate a new line. For example, that can be a simple '\n' on
    typical Unix-like machines, '\n\r' or '\r\n' on other operating systems,
    and on a number of older systems, it could be converted to and from a fixed-size block with a character count at the the beginning of the
    block. There's no requirement that it be the Unicode line feed character.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Janis Papanagnou on Wed Jul 17 09:26:26 2024
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    On 11.07.2024 01:25, Ben Bacarisse wrote:

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

    [...]
    Compare it to 'enum' constants. When I code or debug I want to track
    (search and find) them by name not by integer number.
    Similar with the 'enum' bool type we introduced (when there was not
    yet a bool type existing in C or C++) with literal constants 'true'
    and 'false'. (Only two values, but still as important.)
    Similar with the dedicated pointer value 0 (these days we used the
    literal 'null'). (Only one value, still useful for tracking eq/ne
    comparisons and initializations.)

    Neither of these analogies illuminates the question, which is How
    is searching for a null pointer value useful. The enum analogy
    suffers both from being much more type specific and from being a
    more distinguished value, unlike NULL which applies to all pointer
    types, and almost certainly is more broadly used than any of the
    named constants defined in an 'enum' type. The bool analogy is a
    more faithful analogy but presents the same question: how is
    searching for a constant like 'true' or 'false' useful? We might
    want to know how a particular variable acquired a particular value
    ('true', say), but for that question it seems much more fruitful to
    search for the variable, or where a particular function is called,
    than it does for search for 'true' or 'false'. Also boolean values
    can be the result of a C operator such as '<' or '&&', so searching
    for 'true' or 'false' need not turn up the expression being sought.
    In fact in the case of booleans I think it is much more likely that
    a value being assigned comes from a C operator than it does from a
    boolean constant.

    Yes, you've said that before. You want to search for nullptr. I
    can't think of how that might help find a real bug, if that's what
    you mean by bug-tracking.

    I was hoping for a story... "Once I had this bug where... and if
    I'd been using nullptr I'd have found it a day earlier" kind of
    thing. I'd found a lot of bugs over the years, but I don't recall
    any that would have been easier to find had I been able to search
    for nullptr.

    I was looking for real-world insight here. Obviously one could
    make up a bug where p = nullptr; was written where, say, p = null -
    ptr; was intended, but that's not what I mean.

    Without such an example, your argument seems to be overly generic.

    That's why I had problems to "explain" the reasons to you; because
    it's so universal a property, so obvious (as I said), that I don't
    know what else I could say. (Likewise with "real-word examples".)
    What example could I give that explains that if you're looking for
    specific dedicated semantical values it's easier to look them up
    by [semantical] name than by a [ambiguous] number. Yes this speeds
    up detection of errors when doing code inspections (for bugs or as
    QA measure), and yes, this was helpful for program development and
    bug detection in [my professional and private] practice.

    Ben explains exactly what he is looking for -- a story -- and you
    respond by not giving him one. What's up with that? Your comment
    that something is obvious, followed by an unanswered rhetorical
    question, is totally lame. Ben is asking (I infer) precisely
    because such a story or example is not obvious to him. I can say
    for sure that it is not obvious to me.

    Would you welcome the introduction of the keyword unity -- with the
    value 1 and type int -- into C because one could then search for it?

    No. (Please don't start to be ridiculous. - Or did you really miss
    the point? - No offense intended.)

    I think it is you who is missing the point. Ben's comment is not a
    suggestion but a question. Moreover as I read the question it is a
    sincere effort to gain some insight into what you think and why.
    And in response rather than try to answer the question in any helpful
    way, instead you ridicule him. This response does nothing to answer
    his question, nor does it give the impression that you are really
    listening. You might want to think about that if you want your
    remarks here to be taken seriously.

    I want to say something about the nature of newsgroup dialog.
    Recently Ben and I had a lengthy exchange where we tried to sort
    out our mutual misunderstandings of the other's reading of a
    particular passage in the C standard. It wasn't easy to get to
    the key underlying assumptions that prompted our respective
    viewpoints. I know from first-hand experience that Ben is a
    smart and thoughtful guy, but despite that we formed radically
    different views about something that seemed "obvious" to both
    of us. (I'm not sure how obvious the views were, in either
    Ben's case or my own, but I do know it took a lot of explanation
    on both sides to get to the point where we understood each
    other, which is an indicator that we thought of our own views as
    obvious.) I think the lesson here is that in many cases it is
    the most "obvious" thoughts that are most in need of explanation.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Keith Thompson on Sun Aug 11 20:52:21 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Hmm. I like the idea of a type-agnostic way to express a "zero"
    value, [but] C's use of 0 for all scalar types strikes me more as
    an historical accident than a design feature.

    I don't think it was an accident at all. It was chosen to be
    consistent with how if(), while(), !, ?:, and so forth, all act.
    There is a very consistent design philosophy there. Sometimes
    people who come from a strong Pascal background don't like it,
    but personally I find the C model easier and more convenient to
    work with than the Pascal model.

    In early C, int was in a very real sense the default type. In B,
    types weren't even explicit, and IIRC variables were effectively "of
    type int", or more precisely a 16-bit PDP-11 word. (I'm glossing
    over some details of B, many of which I don't know). In that
    context 0 made sense as a general-purpose "zero" value.

    My comment is not about the type but about the value. That
    the constant 0 happens to be of type int is irrelevant to
    my conclusions.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Keith Thompson on Mon Aug 12 18:10:44 2024
    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    This posting has inspired me to try using (long)0.0
    whenever a null pointer constant is needed. As for
    example

    (void*){ (long)0.0 }

    as an argument to a variadic function where a pointer
    is expected.

    But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.

    Surely not. Furthermore the form I showed has a point,
    whereas this example is roughly the equivalent of a
    first grade knock-knock joke.

    I was of course joking. I assumed you were as well.

    What is the point of (void*){ (long)0.0 }? I don't believe it's a
    null pointer constant even in C23.

    The null pointer constant is (long)0.0, which it must be for the
    compound literal to work. Besides making it obvious that (long)0.0
    is a null pointer constant, the compound literal is safer than
    using just a cast.

    My example is.

    Your example actually has two null pointer constants: the
    expression being casted, and the full expression casting a null
    pointer constant to (void*). But in neither case is that especially
    obvious. Also the expression you wrote is less safe. For example,
    if it had been written ((void*)('/'/'/'+'/'/'/')), the result would
    still be legal C, and compile without problem, but would very likely
    not be what was desired. By contrast, if the compound literal had
    been written (void*){ (long)1.0 }, it simply would not give a clean
    compile, indicating that something is likely askew.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to James Kuyper on Mon Aug 12 17:42:39 2024
    James Kuyper <jameskuyper@alumni.caltech.edu> writes:

    On 7/10/24 17:23, Keith Thompson wrote:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    [...]

    This posting has inspired me to try using (long)0.0
    whenever a null pointer constant is needed. As for
    example

    (void*){ (long)0.0 }

    as an argument to a variadic function where a pointer
    is expected.

    But surely ((void*)('/'/'/'-'/'/'/')) is more elegant.

    Surely not. Furthermore the form I showed has a point,
    whereas this example is roughly the equivalent of a
    first grade knock-knock joke.

    I was of course joking. I assumed you were as well.

    What is the point of (void*){ (long)0.0 }? I don't believe it's
    a null pointer constant even in C23.

    I think you're right about that.

    The compound literal is not a null pointer constant. I didn't
    say it is. The null pointer constant is (long)0.0, like my
    earlier posting pointed out.

    "An integer constant expression132) ... shall only have operands
    that are ... compound literal constants of arithmetic type that
    are the immediate operands of casts. ... Cast operators in an
    integer constant expression shall only convert arithmetic types to
    integer types, ...", so (long)0.0 is permitted."

    While (void*) looks like a cast, in this context it is a compound
    literal of pointer type, which is not allowed. [..]

    Don't be silly. The compound literal works just fine in the
    context I mentioned for it:

    #include <stdio.h>

    int
    main(){
    printf( " null pointer : %p\n", (void*){ (long)0.0 } );
    return 0;
    }

    Compile it for yourself if you don't believe me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dave_thompson_2@comcast.net@21:1/5 to jameskuyper@alumni.caltech.edu on Sun Aug 25 16:56:28 2024
    On Wed, 10 Jul 2024 11:09:41 -0400, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    NULL is required to expand
    into a null pointer constant ... 0 and (void*)0 are the
    two most likely and common choices.

    ((void*)0)

    Otherwise NULL["foo"] gives quite the wrong result

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dave_thompson_2@comcast.net@21:1/5 to jameskuyper@alumni.caltech.edu on Sun Aug 25 16:55:40 2024
    On Mon, 15 Jul 2024 19:49:08 -0400, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    On 7/15/24 18:51, Lawrence D'Oliveiro wrote:
    [silliness]
    Keep in mind that, in text mode, the <stdio.h> library routines use '\n'
    in memory to represent whatever platform-specific method is used in
    files to indicate a new line. For example, that can be a simple '\n' on typical Unix-like machines, '\n\r' or '\r\n' on other operating systems,
    and on a number of older systems, it could be converted to and from a fixed-size block with a character count at the the beginning of the
    block. There's no requirement that it be the Unicode line feed character.

    I never knew any older system that used a fixed-size block (or rather
    record, which in those days was not the same as block) AND prefix
    count in the same file, although OS/360 et seq used ONE of them.

    And Tandem Enscribe used either offset or count fields (depending on
    structure) at _end_ of block, near but not adjacent to records, except
    for textfiles had prefix counts per line AND word (of nonblanks) --
    but the initial versions of their C implementation couldn't handle
    textfiles, so you had to convert them to and from 'data'.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to dave_thompson_2@comcast.net on Sun Aug 25 17:09:42 2024
    On 8/25/24 4:55 PM, dave_thompson_2@comcast.net wrote:
    On Mon, 15 Jul 2024 19:49:08 -0400, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    On 7/15/24 18:51, Lawrence D'Oliveiro wrote:
    [silliness]
    Keep in mind that, in text mode, the <stdio.h> library routines use '\n'
    in memory to represent whatever platform-specific method is used in
    files to indicate a new line. For example, that can be a simple '\n' on
    typical Unix-like machines, '\n\r' or '\r\n' on other operating systems,
    and on a number of older systems, it could be converted to and from a
    fixed-size block with a character count at the the beginning of the
    block. There's no requirement that it be the Unicode line feed character.

    I never knew any older system that used a fixed-size block (or rather
    record, which in those days was not the same as block) AND prefix
    count in the same file, although OS/360 et seq used ONE of them.

    And Tandem Enscribe used either offset or count fields (depending on structure) at _end_ of block, near but not adjacent to records, except
    for textfiles had prefix counts per line AND word (of nonblanks) --
    but the initial versions of their C implementation couldn't handle
    textfiles, so you had to convert them to and from 'data'.

    The systems that I used that needed that ability didn't put a length at
    the beginning of each block, but ALL the blocks were a fixed size in
    length (perhaps 80 characters) and shorter records were just filled out
    with spaces after the data (thus, the records were images of the 80
    column punched cards that would always have 80 columns of data).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to dave_thompson_2@comcast.net on Sun Aug 25 20:48:21 2024
    On 8/25/24 16:56, dave_thompson_2@comcast.net wrote:
    On Wed, 10 Jul 2024 11:09:41 -0400, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    NULL is required to expand
    into a null pointer constant ... 0 and (void*)0 are the
    two most likely and common choices.

    ((void*)0)

    Otherwise NULL["foo"] gives quite the wrong result

    Correct. Sorry.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to dave_thompson_2@comcast.net on Sun Aug 25 23:46:27 2024
    On 8/25/24 16:55, dave_thompson_2@comcast.net wrote:
    On Mon, 15 Jul 2024 19:49:08 -0400, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

    On 7/15/24 18:51, Lawrence D'Oliveiro wrote:
    [silliness]
    Keep in mind that, in text mode, the <stdio.h> library routines use '\n'
    in memory to represent whatever platform-specific method is used in
    files to indicate a new line. For example, that can be a simple '\n' on
    typical Unix-like machines, '\n\r' or '\r\n' on other operating systems,
    and on a number of older systems, it could be converted to and from a
    fixed-size block with a character count at the the beginning of the
    block. There's no requirement that it be the Unicode line feed character.

    I never knew any older system that used a fixed-size block (or rather
    record, which in those days was not the same as block) AND prefix
    count in the same file, although OS/360 et seq used ONE of them.

    And Tandem Enscribe used either offset or count fields (depending on structure) at _end_ of block, near but not adjacent to records, except
    for textfiles had prefix counts per line AND word (of nonblanks) --
    but the initial versions of their C implementation couldn't handle
    textfiles, so you had to convert them to and from 'data'.

    It's been a long time since I ever worked with systems that supported
    such formats, and I never had to actually work with such formats, so I
    don't really know a lot about them. I've figured out four different
    schemes whereby a system using a fixed block size could keep track of
    whether or not a text line stops inside the block, and if so, where; but
    I'm not sure what methods were actually used, nor which systems used
    them - but for me, the important point about all of those schemes is
    that what the C standard fails to mandate about such things allows a
    conforming implementation of C to use any one of them.

    For most of my career as a programmer, I worked under requirements that
    my code behave as intended on any hosted conforming implementation of C.
    Since we didn't have any systems that used obscure line-ending methods
    in shop, whether my code would have worked on such an implementation was untested, but it was intended to.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Keith Thompson on Sun Aug 25 23:45:46 2024
    On 8/25/24 21:18, Keith Thompson wrote:
    James Kuyper <jameskuyper@alumni.caltech.edu> writes:
    On 8/25/24 16:56, dave_thompson_2@comcast.net wrote:
    On Wed, 10 Jul 2024 11:09:41 -0400, James Kuyper
    <jameskuyper@alumni.caltech.edu> wrote:

    NULL is required to expand
    into a null pointer constant ... 0 and (void*)0 are the
    two most likely and common choices.

    ((void*)0)
    Otherwise NULL["foo"] gives quite the wrong result

    Correct. Sorry.

    A mostly meaningless price of trivia: In C17 and earlier, an excessively literal reading of the standard implies that ((void*)0) is not a null
    pointer constant. It says that a null pointer constant is "An integer constant expression with the value 0, or such an expression cast to type
    void *". It does not say that a parenthesized null pointer constant is
    a null pointer constant. (And (void*)0 is a null pointer constant but
    not a valid definition for NULL.)

    C23 fixes this by updating the wording for parenthesized expressions.

    C17: "A *parenthesized expression* is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the
    unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression."

    C23: "A *parenthesized expression* is a primary expression. Its type,
    value, and semantics are identical to those of the unparenthesized expression."

    I remembered that you had raised this issue before, and I think my
    memory of that issue is what led me to leave out the outer parentheses.
    I'm glad to know that they cleared it up.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)