I'm trying to integrate some C++ code into Fortran. I have a doubt with equivalences between types,
is Fortran integer*1 equivalent to C++ bool ?¿ if not, what is the correct C++ equivalent type?¿
Thank you so much in advance!
quoting from this link :
The INTEGER(1) type should be used for large arrays when memory is at a premium for variables which will have only positive, negative, and zero whole number values within the range of -129 to 127..
So, I'd say its C/C++
equivalent would be a signed char
. The equivalent of bool
is Fortran's logical
type.
EDIT: MSB's answer is way better than mine; you're way better off doing what (s)he suggested.
The best thing to do is to use the Fortran ISO_C_Binding which provides types that match C types. That approach is compiler and platform independent. I'm less sure about C++ types but if you are sure of their C equivalent you should be good. The ISO_C_Binding provides the Fortran type C_BOOL to match the C type _Bool. The binding provides a long list of equivalent types. One place that the list appears is in the chapter "Intrinsic Modules" of the gfortran manual. Also see the "Mixed Language Programming" chapter. While I have cited the gfortran manual, as part of the Fortran 2003 language standard these features aren't particular to that compiler.
PS A comment suggests the use of int8_t. The matching type, on the Fortran side with the ISO C Binding, is C_INT8_T.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.