Sharing Reusable C Headers Between Perl XS Distributions
Introduction Since I last wrote a XS tutorial my knowledge within C has increased this has come from improvements in LLM software that has assisted in improving my knowledge where previously I woul...

Source: DEV Community
Introduction Since I last wrote a XS tutorial my knowledge within C has increased this has come from improvements in LLM software that has assisted in improving my knowledge where previously I would be stuck. This knowledge and software has since enabled me to craft more elegant and efficient XS implementations. Today I will share with you my technique for writing reusable C/XS code. One of the most powerful patterns in XS development is writing your core logic in pure C header files. This gives you: Zero-cost reuse - no runtime linking, no shared libraries, just a #include line. No Perl dependency in the C layer - your headers work in any C project Compile-time inlining - the compiler sees everything, optimises aggressively Simple distribution - headers are installed alongside the Perl module via PM This tutorial walks through the complete pattern step by step, using a minimal working example you can build and run yourself. The Example We will create two distributions: Abacus - a prov