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 21/31] Use ui_file_as_string in gdb/compile/


On 2016-10-19 19:48, Pedro Alves wrote:
Well, there's std::pair in C++03, and std::tuple in C++11.
And C++17 has structured bindings:

  auto [source_file, object_file] = compile_to_object ();

:-)

But I think returning a real named struct is clearer than all that.
See patch below showing the idea.  WDYT?

Well, your last example looks really nice, since it avoids the overhead of writing a class just for one return value, but since we don't have access to C++17 quite yet, a class will have to do.


Btw, would it be good to use references for those strings?

Maybe.  I had kept it using pointers to make it clearer at the
call site that these are output parameters.  Maybe that's
old-school C++ mentality?  That moot with this version of the
patch though, so I can dodge discussing that for now.  :-)

I understand, I don't know which one is best. What's nice with references is that you can't call it with something wrong.

The patch looks good to me... just one missing space...

-static void
-get_new_file_names (char **source_file, char **object_file)
+class compile_file_names
+{
+public:
+  compile_file_names(std::string source_file, std::string object_file)

...here?


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