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 RFA: Initialize variable



Hi,


Ian Lance Taylor wrote:
One such case occurs in build_struct in fortran/decl.c.  The relevant
code is:

	  bool first = true;
	  int first_len;

	  has_ts = (c->initializer->ts.cl
		    && c->initializer->ts.cl->length_from_typespec);

	  for (; ctor; ctor = ctor->next)
	    {
	      /* Remember the length of the first element for checking that
		 all elements *in the constructor* have the same length.  This
		 need not be the length of the LHS!  */
	      if (first)
		{
		  gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
		  gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
		  first_len = ctor->expr->value.character.length;
		  first = false;
		}

	      if (ctor->expr->expr_type == EXPR_CONSTANT)
		gfc_set_constant_character_len (len, ctor->expr,
						has_ts ? -1 : first_len);

How about rewriting this as has_ts = (c->initializer->ts.cl && c->initializer->ts.cl->length_from_typespec);

   /* Remember the length of the first element ...  */
   if (ctor)
     {
        gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
	gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
	first_len = ctor->expr->value.character.length;
     }

for (; ctor; ctor = ctor->next)
{
if (ctor->expr->expr_type == EXPR_CONSTANT)
...
Looks much cleaner to me, except for the fact that now ctor != NULL is established twice.


Cheers,
- Tobi


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