Now that you’ve got a taste of interfacing C-structs with functions from Fortran, it’s a good time to go into more detail on compatible C and Fortran data types. I mentioned earlier that C types are different from Fortran types: int is not exactly integer, and float is not exactly real. What matters, however, is that we have a reliable way to match the compatible data types between C and Fortran such that their internal representation in memory is the same. To that end, a wide array of C-conforming type kind parameters is available out of the box in the iso_c_binding module. Table 11.1 lists them all.
Table 11.1 Type kind parameters available in iso_c_binding and their corresponding types in C (continued)
As you can see from table 11.1, C has many built-in types, and Fortran’s iso_c_binding provides type kind parameters to match them.
The C types bool and complex were introduced in the C99 revision to the C Standard. They may appear as _Bool and _Complex, respectively, in C code that was meant to be compliant with earlier C standards. You can refer back to this table as you write Fortran interfaces with other C code. For now, you don’t need to know any more details about many of these C types and their Fortran siblings. Let’s go back to our TCP server, where we’ll encounter a few new C types, such as int64_t and size_t.
If a C type isn’t supported by your Fortran or C compiler, either you’ll get a compile-time error or the type kind parameter imported from iso_c_binding will have a negative value.