1

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!

2 Answers 2

2

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: M.S.B.'s answer is way better than mine; you're way better off doing what (s)he suggested.

Sign up to request clarification or add additional context in comments.

2 Comments

I would say the equivalent is int8_t since there might exist systems with multibyte char-s.
Fortran logical is frequently 4 bytes but can be one -- risky to match to a type from another language.
2

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.

P.S. A comment suggests the use of int8_t. The matching type, on the Fortran side with the ISO C Binding, is C_INT8_T.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.