Path: utzoo!attcan!uunet!image.soe.clarkson.edu!news From: nelson@sun.soe.clarkson.edu (Russ Nelson) Newsgroups: comp.lang.c Subject: Structure constructors? Message-ID: Date: 22 Mar 90 14:31:21 GMT Sender: news@sun.soe.clarkson.edu Reply-To: nelson@clutx.clarkson.edu Organization: Clarkson University, Potsdam NY Lines: 31 Are there any tricks I can use to fake structure contructors in Turbo C? I'd like to do the following: struct point {int x,y}; /* the structure */ draw_line(struct point from, struct point to); /* called function */ draw_box(struct point topleft, struct point botright) /* calling function */ { draw_line(topleft, point_constructor(botright.x-1, topleft.y)); /* etc.... We all know how to draw a box by now */ } Now, I'm sure I could do it like this: static struct point constructed; #define point_constructor(x,y) ( \ constructed.x = x, \ constructed.y = y, \ constructed) But gosh I'd like to avoid the extra memory store that's required. I'm not too concerned about portability, because I can always fall back to calling a function that returns a structure. Feel free to use any Turbo C tricks that are helpful. -- --russ (nelson@clutx [.bitnet | .clarkson.edu]) Russ.Nelson@$315.268.6667 Violence never solves problems, it just changes them into more subtle problems