Maybe slightly off-topic, but I my opinion, we should avoid preprocessor magic whenever possible. (And I say it despite of (or maybe because of) being the main author of fypp
) It obfuscates code more and makes it also for IDEs more difficult to give meaningful support during development (especially, if it involves joining of strings ab above).
The _setopt_ macro could be easily realized with a simple function:
pure function default_optional(def, opt) result(val)
integer, intent(in) :: def
integer, intent(in), optional :: opt
integer :: val
if (present(opt)) then
val = opt
else
val = def
end if
end function default_optional
[...]
argval = default_optional(42, argval_)
Agreedly, it is painful to define it for each data type you need separately (we use the loop construct in fypp to generate it), but Fortran 202Y generic feature should alleviate that and we wonβt need a pre-processor for that any more.