This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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: [gfortran] PR 15327: Fix merge intrinsic for strings


On Sunday 29 August 2004 22:09, Tobias Schlüter wrote:
> MERGE didn't work for strings because we neither dealt with the string
> length arguments in the argument list correctly, nor did we create copies
> of the strings. I fixed this by modifying gfc_conv_intrinsic_merge such
> that it now calls a new library function, gfc_conv_intrinsic_merge, in the
> case of string valued arguments.

<snip>

_gfortran_copy_string can copy with overlapping variables, so you shouldn't 
need to create a temporary at all.

merge (a, b, flag) should expand to
_result = flag?a:b; _result_length = len(a)
ie. basically the same as the numeric case, but also setting the string 
length.

function foo(a, b, flag)
 character*(*) foo, a, b
 logical flag

 foo = merge(a, b, flag)
end function

Should end up as

void foo (char * result, int _result, char *a, char *b, int *flag,
 int _a, it _b)
{
  _gfortran_copy_string (_result, result, _a, *z ? a ? b);
}

Merge is an elemental function, so the scalarizer should automagically do the 
right thing.

Paul


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