Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C89 structs

Name: Anonymous 2010-08-30 0:37

Hi /prog/. When I program C I usually just use whatever features gcc allows without really worrying about different standards. However, I am now trying to learn strict C89. I know that it's no longer "standard" C, but I want to learn it anyways.

typedef struct {
    int a, b;
} s;


So normally, if I wanted to return an s from a function I would just use return (s) {1, 2};, but apparently that's not allowed in C89. So right now I'm using
s res;
res.a = 1;
res.b = 2;
return res;


Is there a better/shorter way to do this?

Thanks.

Name: Anonymous 2010-08-30 1:04

>>6
Yeah, I thought of that after I posted >>5.

But for the specific example I was working on, it seems like overkill. I'm trying to return a vector (a struct of 3 doubles) so there's not too much overhead when returning it.

I'd also like to be able to do something like:
vector a, b, c, d;

d = add(a, cross(b, c));


and doing it the way you suggested would make that code a lot longer. (although I guess I shouldn't be whining about the length if I'm using C)

So, is it really that bad to return a struct in this case?

And thanks for your help.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List