Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!munnari.oz.au!metro!bunyip!moondance!batserver.cs.uq.oz.au!rhys From: rhys@batserver.cs.uq.oz.au (Rhys Weatherley) Newsgroups: comp.lang.c Subject: Re: What is the really pointing to? Message-ID: <3527@moondance.cs.uq.oz.au> Date: 9 May 90 03:51:33 GMT References: <21910@dartvax.Dartmouth.EDU> Sender: news@moondance.cs.uq.oz.au Reply-To: rhys@batserver.cs.uq.oz.au Distribution: comp Lines: 34 pete@othello.dartmouth.edu (Pete Schmitt) writes: >What is the null pointer really pointing to? >If I define the following: >struct entry >{ > int value; > struct entry *next; >}; >struct entry n1, n2, n3, *list_pointer = &n1; >n1.next = &n2; >n2.next = &n3; >n3.next = (struct entry *) 0; /* <-- what is this pointing to, address 0? */ (struct entry *) 0 will indeed be pointing to address 0 in the virtual address space of the machine, which MAY NOT necessarily be the same as the value NULL, but usually is. Whenever wanting to assign a NULL pointer value you SHOULD use NULL, even if you know it is 0, because sooner or later someone is going to want to port your fantastic program to a different machine that doesn't use 0 for NULL in its C compiler, which could cause some interesting results, especially if later in the program you were to compare 'n3.next' with NULL, instead of (struct entry *) 0! As a similar example, in Modula-2 compilers 0 is usually used as NIL (the Modula-2 equivalent of NULL), but I have seen at least one that uses 0x80000000 (hex) as its NIL value, so it is always best in whatever language you are using, especially C, to use NULL (or some equivalent), even if it is less typing to use 0. Rhys Weatherley, University of Queensland, Australia. G'day!!