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

Dot Operator in Fortran

N_Netto
Beginner
1,524 Views

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
1 Solution
mecej4
Honored Contributor III
1,524 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
mecej4
Honored Contributor III
1,525 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.

0 Kudos
andrew_4619
Honored Contributor II
1,524 Views

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

0 Kudos
N_Netto
Beginner
1,524 Views

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

Thanks. 

0 Kudos
Reply