Daniel Phillips <news-innominate.list.linux.kernel@innominate.de> 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 vonbrand@sleipnir.valparaiso.cl Casilla 9G, Vin~a del Mar, Chile +56 32 672616- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sun Oct 15 2000 - 21:00:12 EST