From 4204d65ff0dd3eaf1e300658d58254ceb27c2c1c Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 31 Jul 2017 22:14:56 -0400 Subject: Use designated initializers for messages I did not realize this syntax was so powerful. --- help.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'help.c') diff --git a/help.c b/help.c index ec4a861..7fc5f42 100755 --- a/help.c +++ b/help.c @@ -29,16 +29,18 @@ static void clientMessage(const struct ClientMessage *msg) { } static void clientMove(int8_t dx, int8_t dy) { - struct ClientMessage msg = { .type = CLIENT_MOVE }; - msg.data.m.dx = dx; - msg.data.m.dy = dy; + struct ClientMessage msg = { + .type = CLIENT_MOVE, + .data.m = { .dx = dx, .dy = dy }, + }; clientMessage(&msg); } static void clientPut(char cell) { - struct ClientMessage msg = { .type = CLIENT_PUT }; - msg.data.p.color = color; - msg.data.p.cell = cell; + struct ClientMessage msg = { + .type = CLIENT_PUT, + .data.p = { .color = color, .cell = cell }, + }; clientMessage(&msg); } -- cgit 1.4.1