* Conventions on struct copying?
@ 2014-06-18 23:31 brian m. carlson
2014-06-19 17:10 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: brian m. carlson @ 2014-06-18 23:31 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]
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
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Conventions on struct copying?
2014-06-18 23:31 Conventions on struct copying? brian m. carlson
@ 2014-06-19 17:10 ` Junio C Hamano
2014-06-19 17:22 ` Jason Pyeron
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2014-06-19 17:10 UTC (permalink / raw)
To: brian m. carlson; +Cc: git
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> I don't know of any place we explicitly copy structs like
> this,...
which should be a reason enough. The first concrete guideline is
"just imitate the existing code".
> but I don't know of any prohibition against it, either.
So now you know ;-).
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Conventions on struct copying?
2014-06-19 17:10 ` Junio C Hamano
@ 2014-06-19 17:22 ` Jason Pyeron
2014-06-20 1:26 ` brian m. carlson
0 siblings, 1 reply; 4+ messages in thread
From: Jason Pyeron @ 2014-06-19 17:22 UTC (permalink / raw)
To: 'Junio C Hamano', 'brian m. carlson'; +Cc: git
> -----Original Message-----
> From: Junio C Hamano
> Sent: Thursday, June 19, 2014 13:11
>
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
> > I don't know of any place we explicitly copy structs like
> > this,...
>
> which should be a reason enough. The first concrete guideline is
> "just imitate the existing code".
>
> > but I don't know of any prohibition against it, either.
>
> So now you know ;-).
To expand, on that do not trust the compiler to do deep copies.
http://stackoverflow.com/questions/2302351/assign-one-struct-to-another-in-c
Hit #1 on https://www.google.com/search?q=c+assignment+of+struct
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- -
- Jason Pyeron PD Inc. http://www.pdinc.us -
- Principal Consultant 10 West 24th Street #100 -
- +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
- -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Conventions on struct copying?
2014-06-19 17:22 ` Jason Pyeron
@ 2014-06-20 1:26 ` brian m. carlson
0 siblings, 0 replies; 4+ messages in thread
From: brian m. carlson @ 2014-06-20 1:26 UTC (permalink / raw)
To: Jason Pyeron; +Cc: 'Junio C Hamano', git
[-- Attachment #1: Type: text/plain, Size: 1285 bytes --]
On Thu, Jun 19, 2014 at 01:22:44PM -0400, Jason Pyeron wrote:
> > -----Original Message-----
> > From: Junio C Hamano
> > Sent: Thursday, June 19, 2014 13:11
> >
> > "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> >
> > > I don't know of any place we explicitly copy structs like
> > > this,...
> >
> > which should be a reason enough. The first concrete guideline is
> > "just imitate the existing code".
Right. The reason I asked is that most of our structures end up
containing pointers, so it wouldn't make sense to do the equivalent of a
memcpy on them anyways. This is just data, so I thought it might be
different. I'll implement an oidcpy function to do the work.
> > > but I don't know of any prohibition against it, either.
> >
> > So now you know ;-).
>
> To expand, on that do not trust the compiler to do deep copies.
I'm not. The definition looks like;
struct object_id {
unsigned char sha1[20];
};
I only want it to memcpy those 20 bytes; there's no pointers or anything
to complicate it.
--
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
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-20 1:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-18 23:31 Conventions on struct copying? brian m. carlson
2014-06-19 17:10 ` Junio C Hamano
2014-06-19 17:22 ` Jason Pyeron
2014-06-20 1:26 ` brian m. carlson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.