Return value from shmat(2) is not portable ?

Stephen Clamage steve at taumet.com
Thu May 9 01:15:51 AEST 1991


newsuser at 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 at taumet.com



More information about the Comp.unix.programmer mailing list