[Lazarus] Request for student project ideas

Hans-Peter Diettrich DrDiettrich1 at aol.com
Mon Sep 14 06:17:28 CEST 2009


Paulo Costa schrieb:

> An interesting idea, but probably too hard for a student project, would 
> be the capability of using a C library without having to manually create 
> the pas file that translates the c header.

This is what ToPas can already do. But...

> That is tedious, error prone 
> and a mess when the .h changes and we continue to use the wrong .pas and 
> strange error creep in.

Right, the translator needs exactly the header files as used to create 
the library.

I'm aware of possible changes in C libraries and header files, and 
that's why now I suggest an Pascal compiler with the added ability to 
process C files. Then that compiler would both compile a changed 
library, and create an Pascal interface unit at the same time. This is 
exactly what the CBuilder does for Delphi.

A transformation of C files into Pascal units, as ToPas can do (to some 
degree), IMO is only a provisional solution. When manual intervention is 
required in this step, it will be required for every following bugfix or 
improvement to the C code.

> Also there are a lot of C libraries that are not available to fpc 
> because nobody had the time to create the bindings. I know that there is 
> h2pas but it is a off line tool and needs a lot of help from the 
> programmer.
> 
> A better way could be to hack a C compiler (GCC ?) and use only the 
> parser and the first compilation stage to have the symbols related to 
> the available functions and structures

This part of ToPas is already finished :-)

> and create the pas header from 
> that information. With such tool we could have almost automatic use of 
> any c library...

The hardest problem I found in ToPas is an automated handling of the 
#defines. They should be classified into literal constants, functions, 
macros, and (incomplete) code snippets - where code snippets IMO are of 
no use in a Pascal unit. Such classification could be done easily by an 
LR parser, but an LL parser only can deal with complete source files.

DoDi





More information about the Lazarus mailing list