libgloss/arm/libcfunc.c: alarm [PATCH]

Nick Clifton
Mon Jul 18 00:08:00 GMT 2005

Hi Shaun,

   Well OK, lets have a discussion about this... :-)

> I prefer to think of the noun as a tuple of the return value and the
> error number, where errno is really just a hack around the fact that C
> doesn't allow you to easily return tuples. 

Actually it can.  Just have it return a pointer to a filled in structure 
containing as many objects as you want the function to return.

OK, so you said "easily" and I guess defining a structure type, putting 
it in a shared header which will be accessible to both the caller and 
callee, and making sure that the memory for the structure is properly 
allocated and freed means that the pointer-to-structure solution is not 
necessarily "easy".

Of course another way to have the function return a tuple of two 
integers would be to have it return a long long...

But this is all rather academic, since the API for these functions is 
already defined.

> So, the return statement is
> really...
> 	return (-1, ENOSYS);
> ... and upon this sentence's translation to C it becomes...
> 	return errno = ENOSYS, -1;

I think that my point is that I do not see setting errno as necessarily 
being part of the return from the function.  I can imagine the situation 
where the programmer might want to set and then reset the value of errno 
before returning from the function.  (Because for example two error 
conditions exist and the more serious one is only detected later on in 
the function).  I can also imagine a situation where a function might 
want to return an error value without setting errno.  (Because for 
example it has called another system function which has failed and set 
errno for it).


More information about the Newlib mailing list