This is the mail archive of the
mailing list for the GCC project.
Re: using C++ STL containers in GCC/gfortran source code
- From: Pedro Alves <pedro at palves dot net>
- To: Jakub Jelinek <jakub at redhat dot com>, Janus Weil <janus at gcc dot gnu dot org>
- Cc: gcc mailing list <gcc at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Fri, 16 Dec 2016 18:52:03 +0000
- Subject: Re: using C++ STL containers in GCC/gfortran source code
- Authentication-results: sourceware.org; auth=none
- References: <CAKwh3qgUN=mTFPg6Ew6Yk9RXgS3CttE7O3cGMQRcLKNqUOjBng@mail.gmail.com> <CAKwh3qii7EFG4VECNOgqF6kXczvwK0jQbQyDcQTnwuzSdSCfRw@mail.gmail.com> <20161216180415.GZ21933@tucnak>
On 12/16/2016 06:04 PM, Jakub Jelinek wrote:
> On Fri, Dec 16, 2016 at 06:55:12PM +0100, Janus Weil wrote:
>> To get to more specific questions ...
>>> Basically the only STL construct used in the Fortran FE right now
>>> seems to be std::swap, and a single instance of std::map in
>> I see that fortran/trans-common.c has:
>> #define INCLUDE_MAP
>> and apparently there is also a INCLUDE_STRING macro. I guess if I want
>> to use std::string I don't #include <string>, but #define
>> INCLUDE_STRING, right? Why are those macros needed, exactly?
> They are needed because system.h poisons lots of things, including malloc
> etc. So including system headers after system.h is problematic.
IMO, GCC's poison (or a variant) should ignore system headers. There's
nothing one can do with those. It's _uses_ in one's code that generally
one wants to prevent with the poisoning.
> That said, using std::string for what you talk in the PR would make it
> impossible to translate it, if you build a sentence as:
> ss << "Argument " << something () << " and '" << something_else () << "'";
> then our framework can't deal with that, translating portions of a sentence
> is not going to be useful for many languages.
> Using *printf or similar formatting strings allows the translator to see
> the whole sentence with arguments, and e.g. when needed can swap
> some arguments using %4$s syntax etc.
The problem is not std::string here, but the stream operators.
And I agree.
GDB has a string_printf function that prints into a std::string, for
std::string hello = string_printf ("%s", "hello world");
That's a function that many C++ projects reinvent.