Sign in Join
Wiki copytemporary

C to Pascal: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11One 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.
22
33While 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.
44
55Each 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.
66
77Problems and solutions are explained in these good articles:
88
99- [[Creating bindings for C libraries]]
1010- [[Common problems when converting C header files]]
1111- [[Pascal for C users]]
1212- [Pitfalls of converting](http://rvelthuis.de/articles/articles-convert.html)
1313
1414## C to Pascal conversion tools and libraries
1515
16-<table>
17-<thead>
18-<tr>
19-<th><p>Name</p></th>
20-<th><p>Notes</p></th>
21-<th><p>Headers</p></th>
22-<th><p>Source</p></th>
23-<th><p>Precompiler</p></th>
24-<th><p>C++</p></th>
25-<th><p>ObjC</p></th>
26-<th><p>Interface</p></th>
27-</tr>
28-</thead>
29-<tbody>
30-<tr>
31-<td><p>[[H2Pas]]</p></td>
32-<td><p>FPC team official yylex-based tool to convert C-headers to Pascal. Issues could be reported on Mantis.</p></td>
33-<td><p>Yes</p></td>
34-<td><p>No</p></td>
35-<td><p>somewhat</p></td>
36-<td></td>
37-<td></td>
38-<td><p>command line or [[H2Paswizard]]</p></td>
39-</tr>
40-<tr>
41-<td><p><a href="http://sourceforge.net/projects/c2pas/">OpenC2Pas</a></p></td>
42-<td></td>
43-<td></td>
44-<td></td>
45-<td></td>
46-<td></td>
47-<td></td>
48-<td></td>
49-</tr>
50-<tr>
51-<td><p><a href="http://www.astonshell.com/freeware/c2pas32/">C2Pas32</a></p></td>
52-<td><p>Freeware, but closed source solution</p></td>
53-<td><p>Yes</p></td>
54-<td><p>Yes</p></td>
55-<td></td>
56-<td></td>
57-<td></td>
58-<td><p>command line</p></td>
59-</tr>
60-<tr>
61-<td><p><a href="http://cc.embarcadero.com/item/26951">C To Pascal Converter</a></p></td>
62-<td></td>
63-<td></td>
64-<td></td>
65-<td></td>
66-<td></td>
67-<td></td>
68-<td></td>
69-</tr>
70-<tr>
71-<td><p><a href="http://www.drbob42.com/delphi/headconv.htm">Dr. Bob's HeadConv</a></p></td>
72-<td></td>
73-<td></td>
74-<td></td>
75-<td></td>
76-<td></td>
77-<td></td>
78-<td></td>
79-</tr>
80-<tr>
81-<td><p><a href="http://rvelthuis.de/programs/convertpack.html">Rudy's Conversion Helper Package</a></p></td>
82-<td><p>On <a href="http://rvelthuis.de/articles/">the site</a> a lot of useful information can be found.</p></td>
83-<td></td>
84-<td></td>
85-<td></td>
86-<td></td>
87-<td></td>
88-<td></td>
89-</tr>
90-<tr>
91-<td><p><a href="https://github.com/WouterVanNifterick/C-To-Delphi">C-To-Delphi</a></p></td>
92-<td><p>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.</p></td>
93-<td><p>Yes</p></td>
94-<td><p>Yes</p></td>
95-<td></td>
96-<td><p>No</p></td>
97-<td><p>No</p></td>
98-<td><p>GUI</p></td>
99-</tr>
100-<tr>
101-<td><p><a href="https://github.com/neslib/Chet">Chet</a></p></td>
102-<td><p>Chet uses the Clang compiler to parse header files, resulting in more accurate translations that require fewer manual adjustments.</p></td>
103-<td><p>Yes</p></td>
104-<td><p>Yes</p></td>
105-<td><p>Yes</p></td>
106-<td><p>No</p></td>
107-<td><p>No</p></td>
108-<td><p>GUI</p></td>
109-</tr>
110-<tr>
111-<td><p>[[Chelper]]</p></td>
112-<td><p>The project started as ObjC converter, thus it does understand ObjC notation. Though development is stalled a few years ago</p></td>
113-<td><p>Yes</p></td>
114-<td><p>No</p></td>
115-<td><p>somewhat - no expressions</p></td>
116-<td><p>No</p></td>
117-<td><p>Yes</p></td>
118-<td><p>command line, GUI as Lazarus Plugin</p></td>
119-</tr>
120-<tr>
121-<td><p><a href="http://sourceforge.net/p/topas">ToPas C-to-Pascal</a></p></td>
122-<td><p>The original author is Hans-Peter Diettrich</p></td>
123-<td></td>
124-<td></td>
125-<td></td>
126-<td></td>
127-<td></td>
128-<td></td>
129-</tr>
130-<tr>
131-<td><p><a href="https://github.com/DrDiettrich/CtoPas/">CToPas</a></p></td>
132-<td><p>The latest one and new implementation by Dr Diettrich</p></td>
133-<td><p>Yes</p></td>
134-<td></td>
135-<td></td>
136-<td></td>
137-<td></td>
138-<td><p>GUI</p></td>
139-</tr>
140-<tr>
141-<td><p><a href="http://sourceforge.net/projects/ctopas/files/">CtoPas</a></p></td>
142-<td></td>
143-<td><p>Yes</p></td>
144-<td><p>Yes</p></td>
145-<td></td>
146-<td></td>
147-<td></td>
148-<td><p>GUI</p></td>
149-</tr>
150-<tr>
151-<td><p><a href="http://www.objectivepascal.com/parser/index.html">Objective Pascal Framework Parser</a></p></td>
152-<td><p>PHP written tool is used by FPC team for Cocoa and iOS bindings. Was designed to handle ObjC specifically</p></td>
153-<td><p>Yes</p></td>
154-<td><p>No</p></td>
155-<td><p>OSX versions only</p></td>
156-<td><p>No</p></td>
157-<td><p>Yes</p></td>
158-<td><p>command line</p></td>
159-</tr>
160-<tr>
161-<td><p>[[SWIG]]</p></td>
162-<td><p>Non pascal based solution; aimed at generating bindings for C++</p></td>
163-<td><p>Yes</p></td>
164-<td><p>Yes</p></td>
165-<td></td>
166-<td><p>Yes</p></td>
167-<td></td>
168-<td><p>|-}</p>
169-<p>There might be much more found online (please add them to this list).</p></td>
170-</tr>
171-</tbody>
172-</table>
16+**Name**
17+
18+**Notes**
19+
20+**Headers**
21+
22+**Source**
23+
24+**Precompiler**
25+
26+**C++**
27+
28+**ObjC**
29+
30+**Interface**
31+
32+[[H2Pas]]
33+
34+FPC team official yylex-based tool to convert C-headers to Pascal. Issues could be reported on Mantis.
35+
36+Yes
37+
38+No
39+
40+somewhat
41+
42+command line or [[H2Paswizard]]
43+
44+[OpenC2Pas](http://sourceforge.net/projects/c2pas/)
45+
46+[C2Pas32](http://www.astonshell.com/freeware/c2pas32/)
47+
48+Freeware, but closed source solution
49+
50+Yes
51+
52+Yes
53+
54+command line
55+
56+[C To Pascal Converter](http://cc.embarcadero.com/item/26951)
57+
58+[Dr. Bob's HeadConv](http://www.drbob42.com/delphi/headconv.htm)
59+
60+[Rudy's Conversion Helper Package](http://rvelthuis.de/programs/convertpack.html)
61+
62+On [the site](http://rvelthuis.de/articles/) a lot of useful information can be found.
63+
64+[C-To-Delphi](https://github.com/WouterVanNifterick/C-To-Delphi)
65+
66+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.
67+
68+Yes
69+
70+Yes
71+
72+No
73+
74+No
75+
76+GUI
77+
78+[Chet](https://github.com/neslib/Chet)
79+
80+Chet uses the Clang compiler to parse header files, resulting in more accurate translations that require fewer manual adjustments.
81+
82+Yes
83+
84+Yes
85+
86+Yes
87+
88+No
89+
90+No
91+
92+GUI
93+
94+[[Chelper]]
95+
96+The project started as ObjC converter, thus it does understand ObjC notation. Though development is stalled a few years ago
97+
98+Yes
99+
100+No
101+
102+somewhat - no expressions
103+
104+No
105+
106+Yes
107+
108+command line, GUI as Lazarus Plugin
109+
110+[ToPas C-to-Pascal](http://sourceforge.net/p/topas)
111+
112+The original author is Hans-Peter Diettrich
113+
114+[CToPas](https://github.com/DrDiettrich/CtoPas/)
115+
116+The latest one and new implementation by Dr Diettrich
117+
118+Yes
119+
120+GUI
121+
122+[CtoPas](http://sourceforge.net/projects/ctopas/files/)
123+
124+Yes
125+
126+Yes
127+
128+GUI
129+
130+[Objective Pascal Framework Parser](http://www.objectivepascal.com/parser/index.html)
131+
132+PHP written tool is used by FPC team for Cocoa and iOS bindings. Was designed to handle ObjC specifically
133+
134+Yes
135+
136+No
137+
138+OSX versions only
139+
140+No
141+
142+Yes
143+
144+command line
145+
146+[[SWIG]]
147+
148+Non pascal based solution; aimed at generating bindings for C++
149+
150+Yes
151+
152+Yes
153+
154+Yes
155+
156+\|-}
157+
158+There might be much more found online (please add them to this list).
173159
174160---
175161*From the Free Pascal wiki, page "C to Pascal", as it stood on 2022-04-19 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history