Difference between revisions of "C to Pascal"

From Free Pascal wiki
Jump to navigationJump to search
m (proper wiki-syntax of botched edit)
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
One of the weakness of the Pascal, compared to C language is lower number of existing libraries. The reason for that, is due to unpopularity of the language itself. There're a lot of libraries already implemented in C, and thus there's no reason to rewrite them to pascal and/or create a Pascal version.  
+
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 C-language. Thus using the existing C-based libraries in Pascal program is a common practice. Also need to note, that since the most popular Operating System low level APIs are designed to be used by by C-language.
+
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 a header and binaries. In order to use the library the header needs to be converted to pascal and binaries must be used by the Pascal program (in form of statically or dynamically linked library). While usage of the library is resolved by the linker or in the runtime, the task of converting a C-headers to Pascal is far more complicated job.
+
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 arcticles:
+
Problems and solutions are explained in these good articles:
 
* [[Creating bindings for C libraries]]
 
* [[Creating bindings for C libraries]]
 
* [[Common problems when converting C header files]]
 
* [[Common problems when converting C header files]]
 +
* [[Pascal for C users]]
 +
  
It needs to be noted that the task of converting C headers to Pascal headers could be done by a machine (to some extent, but unlikely could to be done 100%). There has been many utilities written in order to automate the task.
+
==C to Pascal conversion tools and libraries==
 
 
==C to Pascal converstion tools and libraries==
 
 
{| class="wikitable sortable" width="100%"
 
{| class="wikitable sortable" width="100%"
 
! Name  
 
! Name  
 
! Notes
 
! Notes
| Headers
+
! Headers
| Source
+
! Source
| Precompiler
+
! Precompiler
| C++
+
! C++
| ObjC
+
! ObjC
| Interface
+
! Interface
 
|-
 
|-
 
| [[H2Pas]]
 
| [[H2Pas]]
Line 29: Line 29:
 
|  
 
|  
 
|
 
|
| command line or [[h2paswizard]]
+
| command line or [[H2Paswizard]]
 
|-
 
|-
 
| [http://sourceforge.net/projects/c2pas/ OpenC2Pas]
 
| [http://sourceforge.net/projects/c2pas/ OpenC2Pas]
Line 41: Line 41:
 
|-
 
|-
 
| [http://www.astonshell.com/freeware/c2pas32/ C2Pas32]
 
| [http://www.astonshell.com/freeware/c2pas32/ C2Pas32]
|  
+
| Freeware, but closed source solution
|  
+
| {{Yes}}
|  
+
| {{Yes}}
 
|  
 
|  
 
|  
 
|  
 
|
 
|
|  
+
| command line
 
|-
 
|-
 
| [http://cc.embarcadero.com/item/26951 C To Pascal Converter]
 
| [http://cc.embarcadero.com/item/26951 C To Pascal Converter]
Line 93: Line 93:
 
|
 
|
 
|  
 
|  
 +
|-
 +
| [https://github.com/DrDiettrich/CtoPas/ CToPas]
 +
| The latest one and new implementation by Dr Diettrich
 +
| {{Yes}}
 +
|
 +
|
 +
|
 +
|
 +
| GUI
 
|-
 
|-
 
| [http://sourceforge.net/projects/ctopas/files/ CtoPas]
 
| [http://sourceforge.net/projects/ctopas/files/ CtoPas]
 
|
 
|
|  
+
| {{Yes}}
|  
+
| {{Yes}}
 
|  
 
|  
 
|  
 
|  
Line 113: Line 122:
 
|-
 
|-
 
| [[SWIG]]
 
| [[SWIG]]
| Non pascal pased solution
+
| Non pascal based solution; aimed at generating bindings for C++
|  
+
| {{Yes}}
|  
+
| {{Yes}}
|  
+
|
|  
+
| {{Yes}}
 
|  
 
|  
 
|  
 
|  

Revision as of 19:02, 21 May 2019

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

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. Yes No somewhat command line or H2Paswizard
OpenC2Pas
C2Pas32 Freeware, but closed source solution Yes Yes command line
C To Pascal Converter
Dr. Bob's HeadConv
Rudy's Conversion Helper Package On the site a lot of useful information can be found.
Chelper The project started as ObjC converter, thus it does understand ObjC notation. Though development is stalled a few years ago Yes No somewhat - no expressions No Yes command line, GUI as Lazarus Plugin
ToPas C-to-Pascal The original author is Hans-Peter Diettrich
CToPas The latest one and new implementation by Dr Diettrich Yes GUI
CtoPas Yes Yes GUI
Objective Pascal Framework Parser PHP written tool is used by FPC team for Cocoa and iOS bindings. Was designed to handle ObjC specifically Yes No OSX versions only No Yes command line
SWIG Non pascal based solution; aimed at generating bindings for C++ Yes Yes Yes