Welcome to Duncan White's Practical Software Development (PSD) Pages.

I'm Duncan White, an experienced and professional programmer, and have been programming for well over 30 years, mainly in C and Perl, although I know many other languages. In that time, despite my best intentions:-), I just can't help learning a thing or two about the practical matters of designing, programming, testing, debugging, running projects etc. Back in 2007, I thought I'd start writing an occasional series of articles, book reviews, more general thoughts etc, all focussing on software development without all the guff.

See all my Practical Software Development (PSD) Pages

picture of D. White


TEFEL #2: Another Example of a TEFEL tool: Go-style Interfaces in C, Part 2

Recap of Part 1:

Our First Goal: Generate the .h file from the .interface file

Our Second Goal: Generate the .c file from the .interface file

Our Third Goal: Better checking of package functions

Our Fourth Goal: Automatic generation of flag variables

Summary

I have now shown how to implement two TEFEL-style tools (cint and cpkg) to transform C+Interfaces and C+Packages input syntax into plain C. For the first time, to enhance reuse, these tools have much of the shared support code broken out into Support.pm (for most of the parsing code, generalised) and Sig.pm (for code to generate function signatures). In particular, this has shown that the shared support code is highly reusable, and we saw how easy it made building cpkg as - frankly - an afterthought. Writing 100 lines of Perl code to implement cpkg, the vast majority of which were already present in cint, was no more than half an hour's work. This shows that TEFEL can be almost an experimental what if we do this? technique.

Of course the implementation technique (libdl) is currently platform dependent, which is not ideal. If anyone can think of a way of making this more portable, please tell me?

Update: since writing this, I've discovered: http://jamesgregson.blogspot.com/2010/01/portable-dynamic-libraries.html that addresses this question for Linux, Windows and MacOS. His examples are C++ but I'm sure one can easily turn them into C.

If anyone would like to take James's technique, adapt it for C, and check that it still works reliably on Linux, MacOS and Windows, and then adapt cint and lookup_function() to replace libdl calls with calls via James's portability layer, please let me know the results.


d.white@imperial.ac.uk
Back to PSD Top
Written: August 2019