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

Re: [PATCH] objects: scope count variable to loop

From
BWBrandon Williams <bmwill@google.com>
Date
Jul 19, 2017, 18:23 UTC
Message-ID
<20170719182342.GA158344@google.com>
In-Reply-To
<20170719181956.15845-1-sbeller@google.com>
On 07/19, Stefan Beller wrote:
Show 19 quoted lines
> This is another test balloon to see if we get complaints from people
> whose compilers do not support variables scoped to for loops.
> 
> This part of the code base was chosen as it is very old code that does
> not change often, such that a potential revert is easy.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> 
> This is a rather aggressive test ballon, my compiler needed some
> good arguments to accept the new world order:
> 
> object.c: In function ‘object_array_remove_duplicates’:
> object.c:404:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
>   for (unsigned src = 0; src < nr; src++) {
>   ^
> object.c:404:2: note: use option -std=c99 or -std=gnu99 to compile your code
> 
> Using -std=c99 works for me.
This would need a change to the makefile then wouldn't it?
Show 28 quoted lines
> 
> Thanks,
> Stefan
> 
>  object.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/object.c b/object.c
> index f818777412..af26ee2fbc 100644
> --- a/object.c
> +++ b/object.c
> @@ -397,11 +397,11 @@ static int contains_name(struct object_array *array, const char *name)
>  
>  void object_array_remove_duplicates(struct object_array *array)
>  {
> -	unsigned nr = array->nr, src;
> +	unsigned nr = array->nr;
>  	struct object_array_entry *objects = array->objects;
>  
>  	array->nr = 0;
> -	for (src = 0; src < nr; src++) {
> +	for (unsigned src = 0; src < nr; src++) {
>  		if (!contains_name(array, objects[src].name)) {
>  			if (src != array->nr)
>  				objects[array->nr] = objects[src];
> -- 
> 2.14.0.rc0.3.g6c2e499285
> 
-- 
Brandon Williams
Previous: Stefan BellerNext: Jeff King
Message 24 of 39 in “strbuf: use designated initializers in STRBUF_INIT”
  1. strbuf: use designated initializers in STRBUF_INITJeff King, Jul 10, 2017
  2. Ben PeartJul 10, 2017
  3. Jeff KingJul 10, 2017
  4. Ben PeartJul 10, 2017
  5. Mike HommeyJul 11, 2017
  6. Junio C HamanoJul 11, 2017
  7. Ævar Arnfjörð BjarmasonJul 12, 2017
  8. Junio C HamanoJul 12, 2017
  9. Johannes SixtJul 13, 2017
  10. Junio C HamanoJul 10, 2017
  11. Stefan BellerJul 10, 2017
  12. Junio C HamanoJul 10, 2017
  13. Andreas SchwabJul 10, 2017
  14. Johannes SixtJul 10, 2017
  15. Junio C HamanoJul 10, 2017
  16. Johannes SixtJul 10, 2017
  17. Junio C HamanoJul 10, 2017
  18. Junio C HamanoJul 14, 2017
  19. Stefan BellerJul 14, 2017
  20. Jeff KingJul 14, 2017
  21. Junio C HamanoJul 14, 2017
  22. Junio C HamanoJul 14, 2017
  23. objects: scope count variable to loopStefan Beller, Jul 19, 2017
  24. Brandon WilliamsJul 19, 2017
  25. Jeff KingJul 24, 2017
  26. Stefan BellerJul 24, 2017
  27. Jeff KingJul 24, 2017
  28. Ævar Arnfjörð BjarmasonJul 14, 2017
  29. Junio C HamanoJul 14, 2017
  30. Mike HommeyJul 14, 2017
  31. Jeff KingJul 15, 2017
  32. Jeff KingJul 11, 2017
  33. brian m. carlsonJul 11, 2017
  34. Stefan BellerJul 11, 2017
  35. brian m. carlsonJul 11, 2017
  36. Johannes SixtJul 11, 2017
  37. brian m. carlsonJul 12, 2017
  38. Johannes SixtJul 12, 2017
  39. Brandon WilliamsJul 10, 2017

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.