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

Logical Variable in mixed programming.

ayaz
Beginner
394 Views
I am working on a mixed programming project (C++ and Fortran). I am using MS VC++ 6.0 and CVF 6.6B. I want to share variables, which are defined in Fortran to C++ side.

Could any boday help me, how can I share Fortran's "Logical variables" at C++ side.
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
394 Views
Basically, it's the same as integer/int. In C++, it can be also spelled as a BOOL or bool. What makes it LOGICAL is more context than its contents.

C/C++ treat logical expressions as false if their value is zero, and true otherwise. Fortran standard does not specify contents of a LOGICAL, only behaviour.

The only potential gotcha is CVF default convention where only least-significant byte of a LOGICAL is tested (it is a historic remnant from VAX days) -- if it's zero, it evaluates to .FALSE., otherwise .TRUE. Other bits are not tested. Thus:
logical:: b
b = 1
write(*,*) b  !Outputs "T"
b = 2
write(*,*) b  !Outputs "F"
/fpscomp:logicals compiler switch changes that behaviour, so that it's the same as C++ (0=.false., /=0 =.true.)

Jugoslav
0 Kudos
Reply