Martinsos / edlib

Lightweight, super fast C/C++ (& Python) library for sequence alignment using edit (Levenshtein) distance.
http://martinsos.github.io/edlib
MIT License
493 stars 162 forks source link

Edlib and C (and C++) #80

Open Martinsos opened 7 years ago

Martinsos commented 7 years ago

I should check if Edlib works for C - if I am correct, I don't have any extern C directives in edlib.cpp, meaning that it would not work correctly for C! I should either fix that (if it is a problem) and have it work for C correctly, or I should abandon support for C.

I could also consider implementing different interfaces for C++ and C - but that would further complicate docs and I am not sure that is something I want.

Martinsos commented 7 years ago

Currently it is fine, there is no need to add extern "C" to implementation if it is added to header! Edlib currently works like this: edlib.cpp is compiled with C++ compiler, but all symbols (API) are exported as C symbols and can be used by C code. It can also be used by C++ code, since it will also see extern "C" and know how to handle the API.

If we wanted to have two APIs, one richer for C++ and one for C, we could do one of following (I am writing it down to have it for future reference, as I always forget this):

  1. Implement C++ API in edlib.hpp file, which is included in edlib.cpp. They would compile as C++ code to edlib.o and C++ code would use them by including edlib.hpp file. For C API, we would create edlib_c.h file and edlib_c.cpp file, where .h file would define C API (and have extern C keyword) and .cpp would include both edlib.hpp and edlib_c.h and would implement C API, basically it would implement functions that call functions from C++ API (edlib.hpp). edlib_c files would compile as C++ code to edlib_c.o code but depend on edlib.o. C code would then use edlib_c.o, and C++ code would use edlib.o.

  2. We have edlib.h and edlib.cpp. Edlib.h has both C++ API and C API, whre C API is wrapped in extern "C" directive. in edlib.cpp, both C++ API and C API are implemented, C API in such way that it call C++ API. edlib.cpp and edlib.h are then compiled with C++ compiler to edlib.o, which can then be used from both C and C++ code by including edlib.h header and edlib.o.

Actually, 1. approach is just approach 2. broken down into more components, so it comes down to the same thing. We can split just source files, or both source files and headers.

Martinsos commented 6 years ago

I feel more and more like I should drop support for C and just focus on C++ -> it will make development easier, I will be able to define much nicer/cleaner interface, and I think almost nobody uses it in C. If somebody wants to use it in C, they can still write an an interface for it.