C-Fortran interface type in CFI_cdesc_t

I must say this difference is annoying. Imagine writing a helper function to check an array descriptor has a signed integer type. On co-processors for gfortran, Intel, NAG you need to write:

bool is_signed_integer(CFI_type_t type) {
    switch (type) {
        case CFI_type_int8_t:
        case CFI_type_int16_t:
        case CFI_type_int32_t:
        case CFI_type_int64_t:
            return true;
        default:
            return false;
    }
}

Adding other types like CFI_type_int will result in a duplicate case label error.

In flang on the other hand you need to write:

bool is_signed_integer(CFI_type_t type) {
    switch (type) {
        case CFI_type_short:
        case CFI_type_int:
        case CFI_type_long:
        case CFI_type_long_long:
        case CFI_type_int8_t:
        case CFI_type_int16_t:
        case CFI_type_int32_t:
        case CFI_type_int64_t:
        case CFI_type_int128_t:
        case CFI_type_int_least8_t:
        case CFI_type_int_least16_t:
        case CFI_type_int_least32_t:
        case CFI_type_int_least64_t:
        case CFI_type_int_least128_t:
        case CFI_type_int_fast8_t:
        case CFI_type_int_fast16_t:
        case CFI_type_int_fast32_t:
        case CFI_type_int_fast64_t:
        case CFI_type_int_fast128_t:
        case CFI_type_intmax_t:
        case CFI_type_intptr_t:
        case CFI_type_ptrdiff_t:
            return true;
        default:
            return false;
    }
}

In this article from 2013, R. Bader wrote:

The [ISO_Fortran_binding.h] header file is implementation specific and can therefore not be used to bind to different processor within one file scope. Portability is limited to the source level semantics described by the TS.

I already accepted the fact there is no ABI compatbility due to differences in layout of the CFI_cdesc_t struct, as discussed in Is ISO_Fortran_binding.h compatible for different Fortran ABIs? - #4 by awvwgk). However this type quirk also compromises source-level portability of the C code

1 Like