home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!netnews!bandy
- From: bandy@netnews.jhuapl.edu (Mike Bandy)
- Subject: Re: Returned struct
- Message-ID: <BxC0uv.H22@netnews.jhuapl.edu>
- Organization: JHU/Applied Physics Laboratory
- References: <1992Nov5.075611.14809@piccolo.cit.cornell.edu>
- Date: Sat, 7 Nov 1992 06:04:07 GMT
- Lines: 39
-
- sl14@crux3.cit.cornell.edu (Stephen Lee) writes:
-
- >How can one make use of a struct returned by a function? e.g.
-
- >struct complex complex_add(struct complex a, struct complex b);
-
- >I tried
-
- >struct complex z1, z2, z3;
-
- >z1.x = 0; z1.y = 3;
- >z2.x = 5; z2.y = 4;
-
- >z3 = complex_add(z1, z2);
-
- >But BC++ 2.0 complained 'illegal structure operation' on the above.
- >Note: I'm using C, not C++.
-
- I'm not familar with BC++ but in my old VAX/VMS days I saw this sort of thing
- happen when the size of the thing being passed/returned was too big to be
- pushed on the stack or loaded into a register or something like that. The
- solution was to pass/return the ADDRESS of the structure. So I'd change
- the routine to look like:
-
- complex_add(struct complex *a, struct complex *b, struct complex *result);
-
- Then references to variables withing complex_add() have to change like:
-
- result->x = a->x + b->x;
-
- And the call becomes:
-
- complex_add(&z1, &z2, &z3);
-
- --
-
- Mike Bandy
- bandy@aplcomm.jhuapl.edu
- Johns Hopkins University / Applied Physics Lab
-