Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!gatech!mcnc!rti!xyzzy!throopw From: throopw@dg-rtp.dg.com (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: Pointer Stew Message-ID: <5951@xyzzy.UUCP> Date: 13 May 89 04:53:38 GMT References: <387@spec0.UUCP> Sender: usenet@xyzzy.UUCP Lines: 25 > blm@spec0.UUCP (Bharat Lal Madhyani) Everybody pointed out that the type (int [N][M]) is NOT implemented as an array of pointers. But nobody seemed to see the problem in the first program (shown here abbreviated): > char *path[] = { > "/usr/pgmr/junk", > [...] > 0 }; > char **p_path = path ; /* pointer to path */ > main() { while ( **p_path ) printf("%s\n", *p_path++ ); } Does nobody see anything wrong with the condition of that while loop? Anybody? Yes, you in the back with the plastic pocket protector? That's right, it dereferences the null pointer. It may work on some machines, but it is NOT portable at all. Later examples in the same posting get this right, by replacing the zero with an empty string. The other way to correct it is to make the test on (*p_path) instead of (**p_path). -- "You'd be surprised... they're all separate little countries down there." --- Ronald Wilson Reagan Wayne Throop !mcnc!rti!xyzzy!throopw