Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 415

redefine intrinsic operator

$
0
0

I am a little confused of the default operation of intrinsic operator(==), here's the example:

program main
    implicit none

    if('a' == 96) print*, 1
    if('a' == 97) print*, 2
    if('a' == 98) print*, 3

end

there's no output when program executes. And what's more, when extending the operator(==) to deal with character-integer comparison, As:

module test
    implicit none

    interface operator(==)
        module procedure :: equals
    end interface operator(==)

    contains

    function equals(c, value)

    logical               :: equals
    character, intent(in) :: c
    integer,   intent(in) :: value

    equals = (c == char(value))

    end function equals

end module test

The compiler generates an error message:

error #6748: The type/rank for the arguments of this specific function for a defined OPERATOR redefines intrinsic expression operations.   [EQUALS]

So how does the operator(==) work when dealing with operands other than character-character ? And is it extensible? Appriciate any help.

PS: The user-defined extension of other intrinsic comparison operators such as (>, <, >=, <=) are all fine when dealing with character-integer operands.


Viewing all articles
Browse latest Browse all 415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>