This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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, libgfortran] PR47778 reading two arrays of structures from namelist fails


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


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