Subject: Re: remember that warning about __syscall()?
To: Olaf Seibert <rhialto@polder.ubc.kun.nl>
From: Jules Bean <jmlb2@hermes.cam.ac.uk>
List: current-users
Date: 01/03/1997 15:24:13
On Fri, 3 Jan 1997, Olaf Seibert wrote:

> Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu> wrote:
> > The problem was that __syscall() was being used inconsistently --
> > sometimes it was being treated as if it returned an off_t, sometimes
> > it was being treated as if it returned a pointer, sometimes it was
> > being treated as if it returned an 'int'.
> >
> > That's actually _correct_.  It does, in fact, return those different
> > types, depending on the call, rather than returning an off_t.
> > however, it's impossible to prototype a function to have multiple
> > return types...
> 
> __syscall() could be prototyped to return a *union* of all these things.
> 
> At the locatation where the actual value is returned, it requires a cast
> of the value to this union, however, and this is not possible in
> Standard C. Gcc will allow it, though. For portability, a temporary
> union variable would be required.

Of course you can do this in standard C:

union intandlongandoff_t {
	int	i;
	long	l;
	off_t	o;
}

union intandlongandoff_t foo;

IntFunction(*((int*)(&foo)));

LongFunction(*((long*)(&foo)));

OffTFunction(*((off_t*)(&foo)));


This assumes that all the types align at the bottom address, but I assume
that's allowed...

Jules

/----------------+-------------------------------+---------------------\
|  Jelibean aka  | jules@mailbox.co.uk           |  D7 Wolfson Bldg.   |
|  Jules aka     | jules@virtuality.net          |  Trinity College    |
|  Julian Bean   | jmlb2@cam.ac.uk               |  Cambridge CB2 1TQ  |
+----------------+-------------------------------+---------------------+
|  "Le plus fructeux de tous les arts de vivre, c'est l'art de bien    |
|     vivre." - Ciceron                                                |
\----------------------------------------------------------------------/