[patch, libgfortran] PR47778 reading two arrays of structures from namelist fails

Jakub Jelinek jakub@redhat.com
Sun Feb 27 18:02:00 GMT 2011


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



More information about the Fortran mailing list