This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, libgfortran] PR47778 reading two arrays of structures from namelist fails
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Tobias Burnus <burnus at net-b dot de>
- Cc: Jerry DeLisle <jvdelisle at frontier dot com>, gfortran <fortran at gcc dot gnu dot org>, gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 27 Feb 2011 19:02:00 +0100
- Subject: Re: [patch, libgfortran] PR47778 reading two arrays of structures from namelist fails
- References: <4D6A6EED.9080107@frontier.com> <4D6A8C63.4080002@net-b.de>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Sun, Feb 27, 2011 at 06:39:47PM +0100, Tobias Burnus wrote:
> Jerry DeLisle wrote:
> >--- io/list_read.c (revision 170543)
> >+++ io/list_read.c (working copy)
> >@@ -2985,6 +2985,9 @@
> > {
> > int c;
> > char nml_err_msg[200];
> >+
> >+ snprintf (nml_err_msg, sizeof nml_err_msg, "Internal namelist
> >read error");
>
> Is there a reason that you do not use:
>
> char nml_err_msg[200] = "Internal namelist read error";
>
> That looks simpler too me.
The latter is much more expensive at runtime, as it also clears the
remaining 200 - 29 characters.
You could just use
char nml_err_msg[200];
strcpy (nml_err_msg, "Internal namelist read error");
or even
memcpy (nml_err_msg, "Internal namelist read error",
sizeof "Internal namelist read error");
but snprintf above ought to be optimized into that. Except that it isn't
(sprintf is). So guess something that should be improved in 4.7+.
Jakub