Return value from shmat(2) is not portable ?

Brandon S. Allbery KB8JRR/AA allbery at NCoast.ORG
Sat May 11 11:21:09 AEST 1991


As quoted from <986 at oliver.SUBLINK.ORG> by newsuser at oliver.SUBLINK.ORG (Ugo Cei):
+---------------
| I know, this is not portable either, but my eyes are much more pleased
| since this resembles ``... == (char *) 0'', which IS portable. And
| even my compiler has stopped complaining. Now, my question is: why on
| earth wasn't shmat(2) made to return 0 (NULL) in case of failure ? Are
| there some subtle reasons for this that I am not aware of ?
+---------------

Not so subtle:  ALL system calls return -1 on failure.  No exceptions.  This
is generally handled by assembly language glue in libc.a (the versions of Unix
whose assembler calling conventions I'm familiar with set the "carry" flag to
indicate an error on return from a system call).

In any case, the return value from shmat() is not "portable" anyway, because I
may not want a (char *).  I have a program which uses it as a (double *), for
example.  Now, as it turns out, alignment is guaranteed by the default calling
sequence (you can pass flags to shmat() which can affect this, but the default
is suitably aligned for any type), but it's notoriously difficult to explain
this to C, which is why (void *) was invented.

++Brandon
-- 
Me: Brandon S. Allbery			  Ham: KB8JRR/AA  10m,6m,2m,220,440,1.2
Internet: allbery at NCoast.ORG		       (restricted HF at present)
Delphi: ALLBERY				 AMPR: kb8jrr.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery       KB8JRR @ WA8BXN.OH



More information about the Comp.unix.programmer mailing list