Structure constructors?
Russ Nelson
nelson at sun.soe.clarkson.edu
Fri Mar 23 00:31:21 AEST 1990
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 at clutx [.bitnet | .clarkson.edu]) Russ.Nelson@$315.268.6667
Violence never solves problems, it just changes them into more subtle problems
More information about the Comp.lang.c
mailing list