Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.unix.programmer Subject: Re: Return value from shmat(2) is not portable ? Keywords: shmat sysv Message-ID: <715@taumet.com> Date: 8 May 91 15:15:51 GMT References: <986@oliver.SUBLINK.ORG> Distribution: comp Organization: Taumetric Corporation, San Diego Lines: 26 newsuser@oliver.SUBLINK.ORG (Ugo Cei) writes: >From a typical SysV shmat(2) man page: >| char *shmat (shmid, shmaddr, shmflg) ... >| Diagnostics >| ... >| Otherwise, a value of -1 is returned ... >I have always believed that comparing pointers to integers was not >portable, unless the integer is the constant 0 (which is not an >integer at all, in this context). Correct. The man page says that -1 is returned, not ~0, so just compare the return to -1, suitably cast: if((shmaddr = shmat(shmid, shmaddr, shmflg)) == (char *)(-1)) I would not be overly concerned with portability on this, since it is a Unix-specific issue. This code should work on any system supplying shmat. -- Steve Clamage, TauMetric Corp, steve@taumet.com