Re: question about nullptr

Liste des GroupesRevenir à cl c 
Sujet : Re: question about nullptr
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c
Date : 09. Jul 2024, 21:28:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6k6ha$1gsq2$4@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
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. 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?

Date Sujet#  Auteur
6 Jul 24 * question about nullptr145Thiago Adams
6 Jul 24 +- Re: question about nullptr1Bonita Montero
6 Jul 24 +- Re: question about nullptr1John McCue
6 Jul 24 +* Re: question about nullptr114Kaz Kylheku
6 Jul 24 i+- Re: question about nullptr96Janis Papanagnou
6 Jul 24 i+* Re: question about nullptr4bart
7 Jul 24 ii`* Re: question about nullptr3Lawrence D'Oliveiro
7 Jul 24 ii +- Re: question about nullptr1Keith Thompson
7 Jul 24 ii `- Re: question about nullptr1bart
12 Jul 24 i`* Re: question about nullptr13Richard Harnden
12 Jul 24 i +* Re: question about nullptr4Kaz Kylheku
13 Jul 24 i i`* Re: question about nullptr3Kaz Kylheku
13 Jul 24 i i +- Re: question about nullptr1James Kuyper
13 Jul 24 i i `- Re: question about nullptr1Keith Thompson
14 Jul 24 i +- Re: question about nullptr1Tim Rentsch
15 Jul 24 i `* Re: question about nullptr7Lawrence D'Oliveiro
16 Jul 24 i  +- Re: question about nullptr1Keith Thompson
16 Jul 24 i  `* Re: question about nullptr5James Kuyper
16 Jul 24 i   +- Re: question about nullptr1Keith Thompson
25 Aug 24 i   `* Re: question about nullptr3dave thompson 2
25 Aug 24 i    +- Re: question about nullptr1Richard Damon
26 Aug 24 i    `- Re: question about nullptr1James Kuyper
6 Jul 24 `* Re: question about nullptr28Richard Damon
6 Jul 24  `* Re: question about nullptr27David Brown
7 Jul 24   +* Re: question about nullptr2Lawrence D'Oliveiro
7 Jul 24   i`- Re: question about nullptr1David Brown
7 Jul 24   +- Re: question about nullptr1Thiago Adams
9 Jul 24   `* Re: question about nullptr23Richard Harnden
9 Jul 24    `* Re: question about nullptr22Chris M. Thomasson
9 Jul 24     `* Re: question about nullptr10Chris M. Thomasson
9 Jul 24      `* Re: question about nullptr9Ben Bacarisse
9 Jul 24       `* Re: question about nullptr8Chris M. Thomasson
9 Jul 24        `* Re: question about nullptr7Chris M. Thomasson
10 Jul 24         +- Re: question about nullptr1Ben Bacarisse
10 Jul 24         `* Re: question about nullptr5James Kuyper
25 Aug 24          `* Re: question about nullptr4dave thompson 2
26 Aug 24           `* Re: question about nullptr3James Kuyper
26 Aug 24            `* Re: question about nullptr2Keith Thompson
26 Aug 24             `- Re: question about nullptr1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal