Daniel Phillips <[EMAIL PROTECTED]> said:
[...]
> It would be nice if we could return a struct consisting of the error and
> result. I'm not sure if this is allowed in C now or not. It didn't
> work when I tried it with gcc: it seems to consider a struct-valued
> function to be a void-valued. Odd.
Odd? It works, has to: It's part of ANSI C. It is implemented by giving the
function a (hidden) pointer to a struct to be filled in, so this is much
slower than just stuffing a value into a register and returning. Plus it
won't work for syscalls with their arguments in registers, for obvious
reasons. Check this out (i686, RH 6.9.5 using kgcc and gcc give right
results):
#include <stdio.h>
struct s {
int error, result;
};
struct s f();
main()
{
struct s x = {0, 0};
x = f();
printf("error: %d, result: %d\n", x.error, x.result);
}
struct s f()
{
struct s xx;
xx.error = 1;
xx.result = 117;
return xx;
}
--
Horst von Brand [EMAIL PROTECTED]
Casilla 9G, Vin~a del Mar, Chile +56 32 672616