This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] RAII-fy make_cleanup_restore_current_thread & friends


On 2017-05-04 10:48, Pedro Alves wrote:
Honestly, I've been thinking more and more that the "empty line after
declarations" no longer makes sense nowaways, given types with
constructors, which I kind of read like a function call, and also
with the desire to exercise the freedom (from a language perspective)
to declare variables not-just-at-the-start-of-a-scope.

In this case, the resulting code looked like this:

      if (current_context->all || current_context->thread_group != -1)
	{
	  scoped_restore_current_thread restore_thread;

	  int pid = 0;
	  if (!current_context->all)
	    {
	      struct inferior *inf
		= find_inferior_id (current_context->thread_group);

	      pid = inf->pid;
	    }
	  iterate_over_threads (proceed_thread_callback, &pid);
	}

The idea was put the "pid" variable closer to where
it's used, and the scoped_restore's ctor at the top of the scope,
kind of mirroring the fact that the dtor wil run at the end of
the scope.

Anyway, it's certainly a very minor, arguable detail, so I've
moved pid above the empty line.

For the record (and so you don't bring it back to my face later when I do the same :)), I'm fine with declaring varibables close to where they're used. I think this one just looked weird at first, because it's right after another declaration, and we're used to see them grouped together. But with your justification it makes sense.

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]