C to Pascal

One of the weaknesses of Pascal compared to the C language, is a lower number of existing libraries. The reason for that is the much greater popularity of the C language compared to Pascal. Rather than rewrite the existing C libraries in Pascal, an easier alternative is to use the C libraries from Pascal.

While Pascal is a high-level language, it's also "low-level" enough to interact with the very basic API functions used by the C language. Thus, using existing C-based libraries in Pascal programs is a common practice. Also, most of the popular operating systems and low-level APIs are written in and designed to be used by the C language.

Each C language library comes with header files and binaries (static and/or dynamic library file(s)). In order to use the library, the header files need to be converted to Pascal and the binaries must be linked with the Pascal program. While usage of the library is resolved by the linker at compile time (static linking) or at runtime by the OS (dynamic linking), the task of converting a C header file to Pascal is the job of the programmer. However, there have been many utilities written in order to automate or semi-automate the task.

Problems and solutions are explained in these good articles:

C to Pascal conversion tools and libraries

edit

There might be much more found online (please add them to this list).

Name Notes Headers Source Precompiler C++ ObjC Interface
H2Pas FPC team official yylex-based tool to convert C-headers to Pascal. Issues could be reported on Mantis. style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no" No somewhat
OpenC2Pas
C2Pas32 Freeware, but closed source solution style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes
C To Pascal Converter
Dr. Bob's HeadConv
Rudy's Conversion Helper Package On the site a lot of useful information can be found.
C-To-Delphi This tool will convert most of your standard C code. It contains a split view, with C on the left and Delphi on the right. The Delphi code gets updated in real time when you edit the C code. The editors are kept in sync, so you can easily find how a specific piece of code was converted. style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no"
Chet Chet uses the Clang compiler to parse header files, resulting in more accurate translations that require fewer manual adjustments. style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes
Chelper The project started as ObjC converter, thus it does understand ObjC notation. Though development is stalled a few years ago style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no" No somewhat - no expressions style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no"
ToPas C-to-Pascal The original author is Hans-Peter Diettrich
CToPas The latest one and new implementation by Dr Diettrich style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes
CtoPas style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes
Objective Pascal Framework Parser PHP written tool is used by FPC team for Cocoa and iOS bindings. Was designed to handle ObjC specifically style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no" No OSX versions only style="background:#ff9090; color:black; vertical-align: middle; text-align: center; " class="table-no"
SWIG Non pascal based solution; aimed at generating bindings for C++ style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes" Yes style="background: #90ff90; color: black; vertical-align: middle; text-align: center; " class="table-yes"