Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

F_C_STRING is not PURE

jwmwalrus
New Contributor I
280 Views

Hi.

Maybe it's an oversight or maybe I'm missing some reasoning, but shouldn't the following code compile properly?

use ISO_C_BINDING

implicit none

interface
    pure function fnmatch(pattern, string, flags) bind(C, NAME = 'fnmatch')
        import
        integer(C_INT) :: fnmatch
        character(KIND = C_CHAR), intent(in) :: pattern(*), string(*)
        integer(C_INT), value :: flags
    end function
end interface

print *, match('*.f90', 'test.f90')
print *, match('*.f90', 'test.c')

contains
    pure function match(pattern, string) result(res)
        integer(C_INT) :: res
        character(*), intent(in) :: pattern, string
        res = fnmatch(f_c_string(pattern), f_c_string(string), 0_c_int)
    end function
end

If I remove the "pure" prefix from the "match" function, the code compiles and runs correctly on linux ---but I have a hard time switching from my custom (and pure) "f2cstring" function to the standard one.

 

0 Kudos
0 Replies
Reply