null and NULL: is there any difference?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pete

    #16
    Re: null and NULL: is there any difference?

    Darrell Grainger wrote:[color=blue]
    >
    > On Wed, 24 Sep 2003, RHNewBie wrote:
    >[color=green]
    > > Hello,
    > > What is the difference between null and NULL. Are x == null and x ==
    > > NULL the same? The compiler is gcc 3.2.[/color]
    >
    > C language has a NULL but there is no null. When writing I use NULL to
    > indicate the macro defined in <stdlib.h> and when discussing pointers.
    > I use null when discussing the null character.
    > By null character I am referring to '\0'.
    >
    > With that semantics out of the way,
    > if you are asking for the difference
    > between (x == '\0') and (x == NULL) it would depend on what x is.
    > Off the
    > top of my head, they will evaluate to the same result for all x.[/color]

    if x is of type int and NULL is ((void*)0),
    then the result of the comparison is not defined by the standard.

    --
    pete

    Comment

    • BruceS

      #17
      Re: null and NULL: is there any difference?


      "Ben Pfaff" <blp@cs.stanfor d.edu> wrote in message
      news:87fzil4z8i .fsf@pfaff.stan ford.edu...[color=blue]
      > "Malcolm" <malcolm@55bank .freeserve.co.u k> writes:
      >[color=green]
      > > It is annoying if your compiler comes with a header that declares "null"
      > > because of the possibility of confusion. "null" may well be decared the[/color][/color]
      same[color=blue][color=green]
      > > as NULL, or there may be some subtle difference, for instance "null"[/color][/color]
      might[color=blue][color=green]
      > > not be cast to a void * type. You need to check your compiler[/color][/color]
      documentation[color=blue][color=green]
      > > for details.[/color]
      >
      > The compiler is not allowed to declare `null' in any of the
      > standard header. `null' is not part of the reserved namespace.[/color]

      IOW, a conforming implementation must accept something like:

      #include <stdio.h>

      static int new( int class, int object )
      {
      return class - object;
      }

      int main(void)
      {
      int null = 12;
      int instanceof = 54;

      printf("%d\n", new(instanceof, null) );
      return 0;
      }


      ? (assuming I've not introduced an unrelated error)


      Comment

      • Joona I Palaste

        #18
        Re: null and NULL: is there any difference?

        BruceS <nobody@nospam. net> scribbled the following:[color=blue]
        > "Ben Pfaff" <blp@cs.stanfor d.edu> wrote in message
        > news:87fzil4z8i .fsf@pfaff.stan ford.edu...[color=green]
        >> "Malcolm" <malcolm@55bank .freeserve.co.u k> writes:[color=darkred]
        >> > It is annoying if your compiler comes with a header that declares "null"
        >> > because of the possibility of confusion. "null" may well be decared the[/color][/color]
        > same[color=green][color=darkred]
        >> > as NULL, or there may be some subtle difference, for instance "null"[/color][/color]
        > might[color=green][color=darkred]
        >> > not be cast to a void * type. You need to check your compiler[/color][/color]
        > documentation[color=green][color=darkred]
        >> > for details.[/color]
        >>
        >> The compiler is not allowed to declare `null' in any of the
        >> standard header. `null' is not part of the reserved namespace.[/color][/color]
        [color=blue]
        > IOW, a conforming implementation must accept something like:[/color]
        [color=blue]
        > #include <stdio.h>[/color]
        [color=blue]
        > static int new( int class, int object )
        > {
        > return class - object;
        > }[/color]
        [color=blue]
        > int main(void)
        > {
        > int null = 12;
        > int instanceof = 54;[/color]
        [color=blue]
        > printf("%d\n", new(instanceof, null) );
        > return 0;
        > }[/color]

        [color=blue]
        > ? (assuming I've not introduced an unrelated error)[/color]

        Yes. The implementation is allowed to reserve these kind of names
        for itself:
        - anything starting with "mem" or "str" and including zero or more
        lowercase letters after that
        - anything starting with "E" and including one or more uppercase
        letters after that
        - anything starting with an underscore
        Other than those three, you're free to use any names you please, as
        long as they don't contradict with standard names or keywords.

        --
        /-- Joona Palaste (palaste@cc.hel sinki.fi) ---------------------------\
        | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
        | http://www.helsinki.fi/~palaste W++ B OP+ |
        \----------------------------------------- Finland rules! ------------/
        "'So called' means: 'There is a long explanation for this, but I have no
        time to explain it here.'"
        - JIPsoft

        Comment

        • Joona I Palaste

          #19
          Re: null and NULL: is there any difference?

          Joona I Palaste <palaste@cc.hel sinki.fi> scribbled the following:[color=blue]
          > Yes. The implementation is allowed to reserve these kind of names
          > for itself:
          > - anything starting with "mem" or "str" and including zero or more
          > lowercase letters after that[/color]

          Oops. As well as "mem" and "str", the "is" and "to" prefices are also
          reserved.
          [color=blue]
          > - anything starting with "E" and including one or more uppercase
          > letters after that
          > - anything starting with an underscore
          > Other than those three, you're free to use any names you please, as
          > long as they don't contradict with standard names or keywords.[/color]

          --
          /-- Joona Palaste (palaste@cc.hel sinki.fi) ---------------------------\
          | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
          | http://www.helsinki.fi/~palaste W++ B OP+ |
          \----------------------------------------- Finland rules! ------------/
          "It was, er, quite bookish."
          - Horace Boothroyd

          Comment

          • Dan Pop

            #20
            Re: null and NULL: is there any difference?

            In <3F72C942.884@m indspring.com> pete <pfiland@mindsp ring.com> writes:
            [color=blue]
            >Darrell Grainger wrote:[color=green]
            >>
            >> On Wed, 24 Sep 2003, RHNewBie wrote:
            >>[color=darkred]
            >> > Hello,
            >> > What is the difference between null and NULL. Are x == null and x ==
            >> > NULL the same? The compiler is gcc 3.2.[/color]
            >>
            >> C language has a NULL but there is no null. When writing I use NULL to
            >> indicate the macro defined in <stdlib.h> and when discussing pointers.
            >> I use null when discussing the null character.
            >> By null character I am referring to '\0'.
            >>
            >> With that semantics out of the way,
            >> if you are asking for the difference
            >> between (x == '\0') and (x == NULL) it would depend on what x is.
            >> Off the
            >> top of my head, they will evaluate to the same result for all x.[/color]
            >
            >if x is of type int and NULL is ((void*)0),
            >then the result of the comparison is not defined by the standard.[/color]

            The standard actually requires a diagnostic in this case (constraint
            violation).

            Dan
            --
            Dan Pop
            DESY Zeuthen, RZ group
            Email: Dan.Pop@ifh.de

            Comment

            • Jack Klein

              #21
              Re: null and NULL: is there any difference?

              On Wed, 24 Sep 2003 19:58:16 GMT, "Fred L. Kleinschmidt"
              <fred.l.kleinsc hmidt@boeing.co m> wrote in comp.lang.c:
              [color=blue]
              >
              >
              > RHNewBie wrote:[color=green]
              > >
              > > Hello,
              > > What is the difference between null and NULL. Are x == null and x ==
              > > NULL the same? The compiler is gcc 3.2.
              > >
              > > Thanks.[/color]
              > Depends on how you have defined "NULL" and "null". These may or may not
              > be defined in some include file that you include.[/color]

              NULL is required to be defined in a number of standard C headers. It
              produces undefined behavior to try to define it in a program that
              includes any of the standard headers defining it.

              --
              Jack Klein
              Home: http://JK-Technology.Com
              FAQs for
              comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
              comp.lang.c++ http://www.parashift.com/c++-faq-lite/
              alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

              Comment

              • Jack Klein

                #22
                Re: null and NULL: is there any difference?

                On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <palaste@cc.hel sinki.fi>
                wrote in comp.lang.c:
                [color=blue]
                > BruceS <nobody@nospam. net> scribbled the following:[color=green]
                > > "Ben Pfaff" <blp@cs.stanfor d.edu> wrote in message
                > > news:87fzil4z8i .fsf@pfaff.stan ford.edu...[color=darkred]
                > >> "Malcolm" <malcolm@55bank .freeserve.co.u k> writes:
                > >> > It is annoying if your compiler comes with a header that declares "null"
                > >> > because of the possibility of confusion. "null" may well be decared the[/color]
                > > same[color=darkred]
                > >> > as NULL, or there may be some subtle difference, for instance "null"[/color]
                > > might[color=darkred]
                > >> > not be cast to a void * type. You need to check your compiler[/color]
                > > documentation[color=darkred]
                > >> > for details.
                > >>
                > >> The compiler is not allowed to declare `null' in any of the
                > >> standard header. `null' is not part of the reserved namespace.[/color][/color]
                >[color=green]
                > > IOW, a conforming implementation must accept something like:[/color]
                >[color=green]
                > > #include <stdio.h>[/color]
                >[color=green]
                > > static int new( int class, int object )
                > > {
                > > return class - object;
                > > }[/color]
                >[color=green]
                > > int main(void)
                > > {
                > > int null = 12;
                > > int instanceof = 54;[/color]
                >[color=green]
                > > printf("%d\n", new(instanceof, null) );
                > > return 0;
                > > }[/color]
                >
                >[color=green]
                > > ? (assuming I've not introduced an unrelated error)[/color]
                >
                > Yes. The implementation is allowed to reserve these kind of names
                > for itself:[/color]

                Sorry, but all three of these are just a little bit wrong. I've
                pasted in text from the current standard (but it has been the same
                since ANSI 89):
                [color=blue]
                > - anything starting with "mem" or "str" and including zero or more
                > lowercase letters after that[/color]

                "7.26.11 String handling <string.h>
                1 Function names that begin with str, mem, or wcs and a lowercase
                letter may be added to the declarations in the <string.h> header."

                So it's "one or more", not "zero or more".
                [color=blue]
                > - anything starting with "E" and including one or more uppercase
                > letters after that[/color]

                "7.26.3 Errors <errno.h>
                1 Macros that begin with E and a digit or E and an uppercase letter
                may be added to the declarations in the <errno.h> header."

                So it's also E followed by a digit. E2 is reserved, for example.
                [color=blue]
                > - anything starting with an underscore[/color]

                "7.1.3 Reserved identifiers
                1 Each header declares or defines all identifiers listed in its
                associated subclause, and optionally declares or defines identifiers
                listed in its associated future library directions subclause and
                identifiers which are always reserved either for any use or for use as
                file scope identifiers.
                — All identifiers that begin with an underscore and either an
                uppercase letter or another underscore are always reserved for any
                use.
                — All identifiers that begin with an underscore are always reserved
                for use as identifiers with file scope in both the ordinary and tag
                name spaces."

                So the identifiers _1, _2, and so on, are in the user namespace, as
                are _local and such, with a lower case letter in block scope
                variables, and so on.
                [color=blue]
                > Other than those three, you're free to use any names you please, as
                > long as they don't contradict with standard names or keywords.[/color]

                Joona, are you familiar with the American slang expression, "Close,
                but no cigar"?

                --
                Jack Klein
                Home: http://JK-Technology.Com
                FAQs for
                comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

                Comment

                • pete

                  #23
                  [OT]Re: null and NULL: is there any difference?

                  Jack Klein wrote:
                  [color=blue]
                  > Joona, are you familiar with the American slang expression, "Close,
                  > but no cigar"?[/color]

                  I associate that expression with this type of device:


                  Comment

                  • Joona I Palaste

                    #24
                    Re: null and NULL: is there any difference?

                    Jack Klein <jackklein@spam cop.net> scribbled the following:[color=blue]
                    > On 25 Sep 2003 15:07:00 GMT, Joona I Palaste <palaste@cc.hel sinki.fi>
                    > wrote in comp.lang.c:[color=green]
                    >> Yes. The implementation is allowed to reserve these kind of names
                    >> for itself:[/color][/color]
                    [color=blue]
                    > Sorry, but all three of these are just a little bit wrong. I've
                    > pasted in text from the current standard (but it has been the same
                    > since ANSI 89):[/color]
                    [color=blue][color=green]
                    >> - anything starting with "mem" or "str" and including zero or more
                    >> lowercase letters after that[/color][/color]
                    [color=blue]
                    > "7.26.11 String handling <string.h>
                    > 1 Function names that begin with str, mem, or wcs and a lowercase
                    > letter may be added to the declarations in the <string.h> header."[/color]
                    [color=blue]
                    > So it's "one or more", not "zero or more".[/color]
                    [color=blue][color=green]
                    >> - anything starting with "E" and including one or more uppercase
                    >> letters after that[/color][/color]
                    [color=blue]
                    > "7.26.3 Errors <errno.h>
                    > 1 Macros that begin with E and a digit or E and an uppercase letter
                    > may be added to the declarations in the <errno.h> header."[/color]
                    [color=blue]
                    > So it's also E followed by a digit. E2 is reserved, for example.[/color]
                    [color=blue][color=green]
                    >> - anything starting with an underscore[/color][/color]
                    [color=blue]
                    > "7.1.3 Reserved identifiers
                    > 1 Each header declares or defines all identifiers listed in its
                    > associated subclause, and optionally declares or defines identifiers
                    > listed in its associated future library directions subclause and
                    > identifiers which are always reserved either for any use or for use as
                    > file scope identifiers.
                    > — All identifiers that begin with an underscore and either an
                    > uppercase letter or another underscore are always reserved for any
                    > use.
                    > — All identifiers that begin with an underscore are always reserved
                    > for use as identifiers with file scope in both the ordinary and tag
                    > name spaces."[/color]
                    [color=blue]
                    > So the identifiers _1, _2, and so on, are in the user namespace, as
                    > are _local and such, with a lower case letter in block scope
                    > variables, and so on.[/color]
                    [color=blue][color=green]
                    >> Other than those three, you're free to use any names you please, as
                    >> long as they don't contradict with standard names or keywords.[/color][/color]
                    [color=blue]
                    > Joona, are you familiar with the American slang expression, "Close,
                    > but no cigar"?[/color]

                    Yes I am. It comes from old American pinball-type machines where the
                    machine offered minuscule cash prizes, but the main prize was a
                    luxurious cigar. Thanks for the corrections.

                    --
                    /-- Joona Palaste (palaste@cc.hel sinki.fi) ---------------------------\
                    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
                    | http://www.helsinki.fi/~palaste W++ B OP+ |
                    \----------------------------------------- Finland rules! ------------/
                    "O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
                    - Dr. Michael Hfuhruhurr

                    Comment

                    • Dan Pop

                      #25
                      Re: null and NULL: is there any difference?

                      In <bkv0ak$9u2$1@o ravannahka.hels inki.fi> Joona I Palaste <palaste@cc.hel sinki.fi> writes:
                      [color=blue]
                      >Yes. The implementation is allowed to reserve these kind of names
                      >for itself:
                      >- anything starting with "mem" or "str" and including zero or more
                      >lowercase letters after that[/color]

                      s/zero/one
                      [color=blue]
                      >Other than those three, you're free to use any names you please, as
                      >long as they don't contradict with standard names or keywords.[/color]

                      Nope, the list of reserved prefixes is much longer. "is" and "to" are
                      particularly easy to be accidentally used: "iso_name" or "toxicity" are
                      perfectly natural and innocent looking identifiers.

                      Dan
                      --
                      Dan Pop
                      DESY Zeuthen, RZ group
                      Email: Dan.Pop@ifh.de

                      Comment

                      Working...