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

Re: [RFC PATCH v3 0/8] Remote helpers smart transport extensions

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 7, 2009, 20:07 UTC
Message-ID
<7vein635vn.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20091207210608.6117@nanako3.lavabit.com>
Nanako Shiraishi <nanako3@lavabit.com> writes:
Show 7 quoted lines
> Quoting Junio C Hamano <gitster@pobox.com>
>
>> I queued to ease the discussion in 'pu'.  I had to fix-up some conflicts
>> while doing so.  Please sanity check the result.
>
> I see that you changed many "char* variable" to "char *variable", but
> what is the reason for these changes?

Nico already gave you correct and more concise version; this more verbose explanation is primarily for you who said a few times that you are not fluent in C. Others can skip this message without missing anything.

I haven't asked people why they choose to write like this:
	char* string;
beyond "that is how we were taught and what we are used to".

But if I have to guess, it is because it makes it appear as if you are being consistent between basic types like "int" and pointer types like "char *". E.g. these both look like "<type> <variable>;"

	int     variable;
        char*   variable;

The example in CodingGuidelines gives a clear illustration that this however is not the way how C language works. IOW, the syntax for declaration is not "<type> <var1>, <var2>,...;". E.g.

	char*	var1, var2;

declares var1, which is a pointer to a char, and var2, which is a char. That is what Nico means by '* is an attribute of the variable and not of the type'.

The only sane way to read declaration in C is to read from inside to outside, starting from a variable name. When you read "char **argv", for example, you treat it as "char (*(*argv))", and read it from the variable name:

    - It declares argv; what's the type of it I wonder...
    - It is a pointer, because the asterisk in front of it tells us that
      we can dereference it. Now, what's the type of the result of
      dereferencing argv, i.e. "*argv", I wonder...
    - That "*argv" is a pointer, because the asterisk in front of it again
      tells us that we can dereference it. Now, what's the type of
      dereferencing that "*argv", i.e. "**argv", I wonder...
    - Ah, it is a "char", that is what this declaration says.

And the style we use (which is the same as Linux kernel style) naturally matches the way how you read this declaration.

Previous: Nicolas PitreNext: Nanako Shiraishi
Message 20 of 25 in “Remote helpers smart transport extensions”
  1. 0/8 Remote helpers smart transport extensionsIlari Liusvaara, Dec 6, 2009
  2. 1/8 Add remote helper debug modeIlari Liusvaara, Dec 6, 2009
  3. 2/8 Support mandatory capabilitiesIlari Liusvaara, Dec 6, 2009
  4. 3/8 Pass unknown protocols to external protocol handlersIlari Liusvaara, Dec 6, 2009
  5. 4/8 Refactor git transport options parsingIlari Liusvaara, Dec 6, 2009
  6. 5/8 Support taking over transportsIlari Liusvaara, Dec 6, 2009
  7. Shawn O. PearceDec 7, 2009
  8. Ilari LiusvaaraDec 7, 2009
  9. 6/8 Support remote helpers implementing smart transportsIlari Liusvaara, Dec 6, 2009
  10. Shawn O. PearceDec 7, 2009
  11. Ilari LiusvaaraDec 7, 2009
  12. 7/8 Support remote archive from external protocol helpersIlari Liusvaara, Dec 6, 2009
  13. Shawn O. PearceDec 7, 2009
  14. Ilari LiusvaaraDec 7, 2009
  15. 8/8 Remove special casing of http, https and ftpIlari Liusvaara, Dec 6, 2009
  16. Junio C HamanoDec 7, 2009
  17. Nanako ShiraishiDec 7, 2009
  18. Erik Faye-LundDec 7, 2009
  19. Nicolas PitreDec 7, 2009
  20. Junio C HamanoDec 7, 2009
  21. Nanako ShiraishiDec 7, 2009
  22. Jeff KingDec 8, 2009
  23. Jeff KingDec 8, 2009
  24. Ilari LiusvaaraDec 7, 2009
  25. Junio C HamanoDec 7, 2009

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.