git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Conventions on struct copying?

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 18, 2014, 23:31 UTC
Message-ID
<20140618233129.GK368384@vauxhall.crustytoothpaste.net>

I'm still working on the struct object_id patches, and I had a style question. In several places throughout the code, we do something like this:

  unsigned char a[20], b[20];
  /* do some stuff with b */
  hashcpy(a, b);
I could implement an oidcpy that does the same thing.
  struct object_id a, b;
  /* do some stuff with b */
  oidcpy(&a, &b);
Or I could just write that as:
  a = b;

and let the compiler do the heavy lifting. Is there any reason that we'd want the function for that purpose, or is it okay to just use the assignment? I don't know of any place we explicitly copy structs like this, but I don't know of any prohibition against it, either.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Next: Junio C Hamano
Message 1 of 4 in “Conventions on struct copying?”
  1. brian m. carlsonJun 18, 2014
  2. Junio C HamanoJun 19, 2014
  3. Jason PyeronJun 19, 2014
  4. brian m. carlsonJun 20, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.