[Bug fortran/68993] MERGE does not evaluate its arguments
sgk at troutmask dot apl.washington.edu
gcc-bugzilla@gcc.gnu.org
Mon Dec 21 20:56:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68993
--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Mon, Dec 21, 2015 at 08:29:57PM +0000, Joost.VandeVondele at mat dot ethz.ch
wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68993
>
> --- Comment #5 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
> (In reply to Steve Kargl from comment #4)
> >
> > I would urge anyone trying to be clever to use clear syntax:
> >
>
> https://github.com/hfp/libxsmm/commit/cc308fc5debe6151157a4fa9efacc7aa03351283
>
> is what we used indeed, but it is not quite as concise as one would like.
>
Interesting project. I may need to take a closer look at it.
I agree that the suggested syntax is not concise. In your particular
case, you could write
cpa = C_NULL_PTR
IF (PRESENT(pa)) cpa = C_LOC(pa)
instead of
IF (PRESENT(pa)) THEN
cpa = C_LOC(pa)
ELSE
cpa = C_NULL_PTR
END IF
This would reduce your code from 15 lines to 6 lines. I'll note that
in some testing where I had a similar code structure the former
(ie., 2-line example) was slower than the latter (5-line example).
It is unfortanute that Fortran does not have a ternary operator.
This is a good example where it might be nice to have
cpa = present(pa) ? c_loc(pa) : c_null_ptr
where the TRUE or FALSE choice is only evaluated based on the condition.
More information about the Gcc-bugs
mailing list