Carel Fellinger wrote:
On Thu, Mar 21, 2002 at 04:04:01AM +0100, Frank Heckenbach wrote:
Carel Fellinger wrote:
...
I'm probably a bit dim here, but surely you are not saying that it's possible to forgo rewriting the header file into a pascal interface module by `{$include wrapper.c}', are you?
No -- it's {$L wrapper.c}. ;-)
Of course, you still have to write wrapper.c and you need some external declarations in Pascal. For more details, you might want to look at existing interfaces such as RegEx (with the GPC sources), or the mentioned database units, etc. ...
I may be really really dim, but I don't see the big win. You stil have to write your own mappings from C to gpc for *all* C decl's and def's you're going to use, and specify the "assname" for all routines used. The only thing this buys you is that gpc knows what other files to compile and link when you give it the --make or --build option. Something I'm not able to use as my project's build process is to complex for this, so I've to use make anyway.
`gpc --automake' should now be able to cope with complex projects as well (maybe called from a makefile if you need to build other things as well).
Or am I missing something here?
Well, the main advantage is that you use the C header as it's meant to. E.g., if some "functions" declarations are actually macros (or modified by macros), the seemingly matching external declarations in Pascal won't work. (This happened, e.g., with the GMP library -- I didn't use this method there, and the interface broke with GMP 3.x.)
Another area are types. E.g., some C functions use or provide `structs', and the only thing documented about them is that they contain some fields with certain names and types. But it varies (from version to version, or system to system) where the fields are located in the `struct' and which other fields are there. So a matching Pascal `record' declaration is not possible.
Or take constants or enum values. It's not uncommon that some new values are inserted, and some of the constants change their value, in a new version.
In general, the more variation is in the library, the more problems a direct Pascal translation can have which are avoided by using C wrappers. If you only link to one specific version of one specific implementation of a library on one specific platform, you can translate it directly. But when you want to allow different versions, or not limit the program to one platform, or most of all, if there are different independant implementations of a library (e.g., libc or curses), such a direct translation is just asking for trouble.
Frank