{"thread":{"id":"36959","subject":"Conventions on struct copying?","startedAt":"2014-06-18T23:31:29Z","lastAt":"2014-06-20T01:26:08Z","messageCount":4,"participants":["brian m. carlson","Junio C Hamano","Jason Pyeron"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"244610","messageId":"20140618233129.GK368384@vauxhall.crustytoothpaste.net","threadId":"36959","inReplyTo":null,"subject":"Conventions on struct copying?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2014-06-18T23:31:29Z","receivedAt":"2014-06-18T23:31:29Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"I'm still working on the struct object_id patches, and I had a style\nquestion.  In several places throughout the code, we do something like\nthis:\n\n  unsigned char a[20], b[20];\n\n  /* do some stuff with b */\n  hashcpy(a, b);\n\nI could implement an oidcpy that does the same thing.\n\n  struct object_id a, b;\n\n  /* do some stuff with b */\n  oidcpy(&a, &b);\n\nOr I could just write that as:\n\n  a = b;\n\nand let the compiler do the heavy lifting.  Is there any reason that\nwe'd want the function for that purpose, or is it okay to just use the\nassignment?  I don't know of any place we explicitly copy structs like\nthis, but I don't know of any prohibition against it, either.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"244696","messageId":"xmqqvbrwhlki.fsf@gitster.dls.corp.google.com","threadId":"36959","inReplyTo":"20140618233129.GK368384@vauxhall.crustytoothpaste.net","subject":"Re: Conventions on struct copying?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-19T17:10:37Z","receivedAt":"2014-06-19T17:10:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> I don't know of any place we explicitly copy structs like\n> this,...\n\nwhich should be a reason enough.  The first concrete guideline is\n\"just imitate the existing code\".\n\n> but I don't know of any prohibition against it, either.\n\nSo now you know ;-).\n"},{"id":"244698","messageId":"5A7F0CEE2DEC4F1B825568DB8358D397@black","threadId":"36959","inReplyTo":"xmqqvbrwhlki.fsf@gitster.dls.corp.google.com","subject":"RE: Conventions on struct copying?","fromName":"Jason Pyeron","fromEmail":"jpyeron@pdinc.us","sentAt":"2014-06-19T17:22:44Z","receivedAt":"2014-06-19T17:22:44Z","isPatch":false,"sender":{"key":"jpyeron@pdinc.us","avatar":"https://gravatar.com/avatar/c2e53452caa53d940768a1ffc9cf76196d851b9b534b7a39cd39852a70a0508f?d=mp&s=160"},"body":"> -----Original Message-----\n> From: Junio C Hamano\n> Sent: Thursday, June 19, 2014 13:11\n> \n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > I don't know of any place we explicitly copy structs like\n> > this,...\n> \n> which should be a reason enough.  The first concrete guideline is\n> \"just imitate the existing code\".\n> \n> > but I don't know of any prohibition against it, either.\n> \n> So now you know ;-).\n\nTo expand, on that do not trust the compiler to do deep copies.\n\nhttp://stackoverflow.com/questions/2302351/assign-one-struct-to-another-in-c\n\nHit #1 on https://www.google.com/search?q=c+assignment+of+struct\n\n--\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n-                                                               -\n- Jason Pyeron                      PD Inc. http://www.pdinc.us -\n- Principal Consultant              10 West 24th Street #100    -\n- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -\n-                                                               -\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nThis message is copyright PD Inc, subject to license 20080407P00.\n"},{"id":"244731","messageId":"20140620012608.GA856079@vauxhall.crustytoothpaste.net","threadId":"36959","inReplyTo":"5A7F0CEE2DEC4F1B825568DB8358D397@black","subject":"Re: Conventions on struct copying?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2014-06-20T01:26:08Z","receivedAt":"2014-06-20T01:26:08Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Thu, Jun 19, 2014 at 01:22:44PM -0400, Jason Pyeron wrote:\n> > -----Original Message-----\n> > From: Junio C Hamano\n> > Sent: Thursday, June 19, 2014 13:11\n> > \n> > \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> > \n> > > I don't know of any place we explicitly copy structs like\n> > > this,...\n> > \n> > which should be a reason enough.  The first concrete guideline is\n> > \"just imitate the existing code\".\n\nRight.  The reason I asked is that most of our structures end up\ncontaining pointers, so it wouldn't make sense to do the equivalent of a\nmemcpy on them anyways.  This is just data, so I thought it might be\ndifferent.  I'll implement an oidcpy function to do the work.\n\n> > > but I don't know of any prohibition against it, either.\n> > \n> > So now you know ;-).\n> \n> To expand, on that do not trust the compiler to do deep copies.\n\nI'm not.  The definition looks like;\n\n  struct object_id {\n    unsigned char sha1[20];\n  };\n\nI only want it to memcpy those 20 bytes; there's no pointers or anything\nto complicate it.\n\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}