using macros in C to convert multiple arguments into one -
i'm brand new c, , i'm trying following:
i have function move(int x, int y)
want able move(center)
i'm trying "#define center x/2, y/2
"
what right way this?
move(center)
so want able call move
on variable named center
? use struct:
struct point { int x; int y; } ... void move(struct point p) { // read p.x , p.y } ... struct point center; center.x = 20; center.y = 20; move(center);
i'm not sure intent #define center x/2, y/2
part... did mean #define center width/2, height/2
? can center.x = width / 2
, center.y = height / 2
.
edit: if can't re-define move
try like
void my_move(struct point p) { move(p.x, p.y); }
Comments
Post a Comment