BerkeleyLab/caffeine

Add script to automate creation of C signature declarations from BIND(C) interfaces

Opened this issue · 1 comments

Add script to automate creation of C signature declarations from BIND(C) interfaces in caffeine_h_m. Script only needs to be general enough to handle interfaces in caffeine_h_m.

To clarify, the motivation for this request is the fact that bind(C) functions that cross the C-Fortran language barrier have to be redundantly declared (once in each language). The linker effectively checks for spelling errors in the function names that might not match between redundant declarations. However no compiler is capable of checking that the argument signatures for the two declarations for the same function actually match each other, and if/when they do not match the result of calls to those functions can be silent undefined behavior.

This insidious problem has already independently arisen multiple times in the course of Caffeine development, despite the relatively small number of relevant functions. I expect this will be an ongoing QA problem until we devise an automated mechanism to detect such defects.

The idea with this enhancement is an automated script that is just barely smart enough to parse the BIND(C) Fortran interfaces defined in src/caffeine/caffeine_h_m.f90 and emit a generated C header file containing the conforming C-side declarations. That header file can then be #include'd in caffeine.c, enabling the C compiler to detect mismatched function argument signatures and flag an error.