[PATCH 04/19] Use C99 designated initializers in dix Replies

Keith Packard keithp at keithp.com
Tue Jul 3 14:31:41 PDT 2012


Alan Coopersmith <alan.coopersmith at oracle.com> writes:

> I can take a pass over to see about converting all to that style.   Would
> you even want to see it used where the blocks were more natural, such
> as

I'm thinking the most important thing right now is to make it easy to
write and review -- essentially, the changes I'd like to see is where
the object declaration doesn't move, and the very first setting of
anything in the object uses the structure assignment to initialize all
of the fields:

--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1660,9 +1660,11 @@ ProcSetModifierMapping(ClientPtr client)
                             bytes_to_int32(sizeof(xSetModifierMappingReq))))
         return BadLength;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSetModifierMappingReply) {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence
+    };
 
     rc = change_modmap(client, PickKeyboard(client), (KeyCode *) &stuff[1],
                        stuff->numKeyPerModifier);

That gains some of the benefits of not writing stuff twice, while making
the code transformation obvious. Moving the assignments around in the
code means needing to look at the intervening lines to ensure that the
values of the expressions would be the same in both places.

As a bogus example, if 'client->sequence' was modified between the start
and end of this function, a patch would never show it...

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120703/61ccea14/attachment.pgp>


More information about the xorg-devel mailing list