Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
79 Views

Dot Operator in Fortran

Jump to solution

Hi, 

I've updated a code that I'm working on and something caught my attention. I tried to use dot operator to access some data in a custom type (I was working on C++ just before) and the code... just compiled.

I cannot find anything that says that dot operator has the same function as the percentage operator, except in some old non-standard fortran compilers. 

There were some changes in the Fortran standard that allows the dot operator as type accessor?

 

The following code compiled just fine with ifort 19.0.5, x86, Windows 10.

program DotOperatorTest

    implicit none
    
    type :: mytype
        real(8)     :: a, b
        integer(4)  :: i, k
    end type
    
    type(mytype) :: foo
    
    foo%a = 1.5
    foo.b = 2.0
    
    foo.i = int(foo.a * foo%b * 3)
    foo%k = foo%i / foo.b
    
    write(*,'(A,g0)') 'a equals to ', foo%a
    write(*,'(A,g0)') 'b equals to ', foo.b
    write(*,'(A,i0)') 'i equals to ', foo.i
    write(*,'(A,i0)') 'k equals to ', foo%k
    
    pause
    
    end program DotOperatorTest

Returning

a equals to 1.500000000000000
b equals to 2.000000000000000
i equals to 9
k equals to 4
Fortran Pause - Enter command<CR> or <CR> to continue.

 

Thanks

0 Kudos

Accepted Solutions
Highlighted
Black Belt
79 Views

The use of '.' in place of '%' to demarcate components of derived types is a DEC/Compaq/Intel non-standard extension. Its use can make your code behave in odd ways if the code also employs components named 'EQ', 'AND', etc.

View solution in original post

0 Kudos
3 Replies
Highlighted
Black Belt
80 Views

The use of '.' in place of '%' to demarcate components of derived types is a DEC/Compaq/Intel non-standard extension. Its use can make your code behave in odd ways if the code also employs components named 'EQ', 'AND', etc.

View solution in original post

0 Kudos
Highlighted
Valued Contributor III
79 Views

As mecej4 says. Put standards checking on (a good plan with new code) and it will get thrown out.

0 Kudos
Highlighted
Beginner
79 Views

Oh, I see. I was not expecting that new projects have portability options enabled by default.

Thanks. 

0 Kudos