Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Dot Operator in Fortran

N_Netto
Beginner
363 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
Black Belt
363 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

3 Replies
mecej4
Black Belt
364 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

andrew_4619
Honored Contributor I
363 Views

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

N_Netto
Beginner
363 Views

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

Thanks. 

Reply