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] Optimize 'a ' as single char string too


On Tue, Jul 13, 2010 at 11:07:15PM -0700, Steve Kargl wrote:
> If you haven't committed your patch based on my OK,
> can you hold off a bit?  I have received a query about
> whether trailing whitespace in a string needs to be
> omitted by a TRIM call.

I don't quite understand the question
"whether trailing whitespace in a string needs to be omitted by
 a TRIM call."

Assuming your "whitespace" means " " (a space/blank), I would say

a) TRIM should do this as the result is:
   "The value of the result is the same as STRING except any
    trailing blanks are removed."

b) For character comparison, TRIM does not play any role, cf. 
 "For a character relational intrinsic operation, the operands are 
  compared one character at a time in order, beginning with the first
  character of each character operand. If the operands are of unequal
  length, the shorter operand is treated as if it were extended on
  the right with blanks to the length of the longer operand. If both
  x1 and x2 are of zero length, x1 is equal to x2; if every character
  of x1 is the same as the character in the corresponding position in
  x2, x1 is equal to x2. Otherwise, at the first position where the
  character operands differ, the character operand x1 is considered
  to be less than x2 if the character value of x1 at this position
  precedes the value of x2 in the collating sequence (1.3); x1 is
  greater than x2 if the character value of x1 at this position
  follows the value of x2 in the collating sequence."
 (F2008, 7.1.5.5.1 Interpretation of relational intrinsic operations)

Thus, the optimization of ignoring the tailing blanks for
  if (c .eq. 'a ') call abort
seems to be fine.

Tobias


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