git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Purpose of "struct object_entry *oe = oe;"?
@ 2010-06-29 12:28 Bruce Stephens
  2010-07-02  1:43 ` Joshua Juran
  2010-07-02  8:48 ` David Aguilar
  0 siblings, 2 replies; 4+ messages in thread
From: Bruce Stephens @ 2010-06-29 12:28 UTC (permalink / raw)
  To: git

Out of curiousity, where did this convention/idiom come from, and what's
it for?

I presume it's to remove a warning ("oe might be used uninitialised") on
a compiler (or something) that's clever enough to attempt such analysis
but too stupid to notice that the supposed initialisation is using
something uninitialised (or perhaps the compiler's deliberately
recognising the convention?).  Is that right, or does it actually do
something more?

I'm mostly surprised that it surprises me.  Is it used commonly in other
projects?  (It appears not to be mentioned in CodingGuidelines; should
it be?)

(First instance in git that I can see is
67affd5173da059ca60aab7896985331acacd9b4, 2006.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Purpose of "struct object_entry *oe = oe;"?
  2010-06-29 12:28 Purpose of "struct object_entry *oe = oe;"? Bruce Stephens
@ 2010-07-02  1:43 ` Joshua Juran
  2010-07-02  8:48 ` David Aguilar
  1 sibling, 0 replies; 4+ messages in thread
From: Joshua Juran @ 2010-07-02  1:43 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: git

On Jun 29, 2010, at 5:28 AM, Bruce Stephens wrote:

> Out of curiousity, where did this convention/idiom come from, and  
> what's
> it for?
>
> I presume it's to remove a warning ("oe might be used  
> uninitialised") on
> a compiler (or something) that's clever enough to attempt such  
> analysis
> but too stupid to notice that the supposed initialisation is using
> something uninitialised (or perhaps the compiler's deliberately
> recognising the convention?).  Is that right, or does it actually do
> something more?
>
> I'm mostly surprised that it surprises me.  Is it used commonly in  
> other
> projects?  (It appears not to be mentioned in CodingGuidelines; should
> it be?)

I was wondering this myself.  My compiler complains in (and only in)  
the *presence* of this idiom, rather than its absence, so I undid it:

jj/warn/uninitialized branch on GitHub
http://github.com/jjuran/git/tree/jj/warn/uninitialized

jj/warn/uninitialized commit on GitHub
http://github.com/jjuran/git/commit/ 
8affbf2d8e46fbd5f3d6898aa07ea8548432e7bc
Signed-Off-By:  Joshua Juran <jjuran@gmail.com> (or s/gmail/metamage/)

A compiler that warns of uninitialized usage *unless* a variable is  
initialized *with itself* is doubly broken.

Cheers,
Josh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Purpose of "struct object_entry *oe = oe;"?
  2010-06-29 12:28 Purpose of "struct object_entry *oe = oe;"? Bruce Stephens
  2010-07-02  1:43 ` Joshua Juran
@ 2010-07-02  8:48 ` David Aguilar
  2010-07-02  9:28   ` Bruce Stephens
  1 sibling, 1 reply; 4+ messages in thread
From: David Aguilar @ 2010-07-02  8:48 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: git

On Tue, Jun 29, 2010 at 01:28:19PM +0100, Bruce Stephens wrote:
> Out of curiousity, where did this convention/idiom come from, and what's
> it for?
> 
> I presume it's to remove a warning ("oe might be used uninitialised") on
> a compiler (or something) that's clever enough to attempt such analysis
> but too stupid to notice that the supposed initialisation is using
> something uninitialised (or perhaps the compiler's deliberately
> recognising the convention?).  Is that right, or does it actually do
> something more?
> 
> I'm mostly surprised that it surprises me.  Is it used commonly in other
> projects?  (It appears not to be mentioned in CodingGuidelines; should
> it be?)
> 
> (First instance in git that I can see is
> 67affd5173da059ca60aab7896985331acacd9b4, 2006.)


There are some good explanations in the list archives.
http://thread.gmane.org/gmane.comp.version-control.git/133278/focus=133422
http://thread.gmane.org/gmane.comp.version-control.git/124676/focus=124803


-- 
		David

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Purpose of "struct object_entry *oe = oe;"?
  2010-07-02  8:48 ` David Aguilar
@ 2010-07-02  9:28   ` Bruce Stephens
  0 siblings, 0 replies; 4+ messages in thread
From: Bruce Stephens @ 2010-07-02  9:28 UTC (permalink / raw)
  To: David Aguilar; +Cc: git

David Aguilar <davvid@gmail.com> writes:

[...]

> There are some good explanations in the list archives.
> http://thread.gmane.org/gmane.comp.version-control.git/133278/focus=133422
> http://thread.gmane.org/gmane.comp.version-control.git/124676/focus=124803

Thanks.  That matches my guess.

Wouldn't it be useful to mention it in CodingGuidelines?

A danger is that the declaration (that yes, this really is initialised
before use) becomes invalid during further changes, so it's best if
everybody concerned understands the convention.

Obviously if it's a commonly understood and used convention then it's
just as well not to have it in CodingGuidelines, but I'm not convinced
that this one is, though (having noticed it) the intention isn't hard to
grok.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-07-02  9:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-29 12:28 Purpose of "struct object_entry *oe = oe;"? Bruce Stephens
2010-07-02  1:43 ` Joshua Juran
2010-07-02  8:48 ` David Aguilar
2010-07-02  9:28   ` Bruce Stephens

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).