Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!sol.ctr.columbia.edu!emory!gatech!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/AA) Newsgroups: comp.unix.programmer Subject: Re: Return value from shmat(2) is not portable ? Message-ID: <1991May11.012109.5050@NCoast.ORG> Date: 11 May 91 01:21:09 GMT References: <986@oliver.SUBLINK.ORG> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR/AA) Followup-To: comp.unix.programmer Distribution: comp Organization: North Coast Public Access Un*x (ncoast) Lines: 27 As quoted from <986@oliver.SUBLINK.ORG> by newsuser@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@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