[fpc-devel] Hi listers, , , , I am trying to translate a C headerwith H2PAS
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Tue Jun 21 12:35:15 CEST 2011
Skybuck Flying schrieb:
> What's so hard about converting a C to a Pascal file, even partial
> conversion might still be somewhat usefull.
Many tools (e.g. h2pas) exist for partial conversions (of header files).
A reliable conversion requires e.g. the exact header files for all data
types. Remember that C has no fixed-size data types at all?
> In can imagine the converter might need to know where certain "includes"
> are but that's pretty much it...
The header files in turn rely on certain compiler-supplied #defines,
which also must be supplied. Fortunately the number of existing
compilers is not so big, so that I started to supply some configs for
gcc, BCB and VS. The user still has to select the applicable compiler,
or derive his own default settings from the supplied samples.
Also the interpretation of the source code, even the C language specs,
varies amongst compilers. I had to add several hacks for e.g. MSVC, and
specific #pragma implementations may be required for other compilers.
This means that the user *must* select an existing compiler, what should
be not so hard in the concrete case (MSVC), but may lead to
unpredictable mismatches in data types in other cases (gcc), which can
make the result incompatible with concrete (binary) libraries.
> Some gui where additional files/paths could be set would be sufficient ?!?
That's doable for directories, of course, but I postponed any GUI
development until solutions for the more important problems can be
found. Most critical is the determination, which #defines should
translate into named constants, subroutine calls, or must be substituted
by the preprocessor. The Windows headers with their *thousands* of
#defines still wait for an according classification - be manual or
automatic. This was the point when I stopped further work on ToPas. It
works as-is, but its correct usage (for reliable results) requires some
additional knowledge.
I do *not* want to provide unreliable software, that is easy to use, but
may provide incorrect results when configured in a wrong way. While FPC
or Lazarus report errors when used with a wrong configuration, a source
code converter cannot determine whether its configuration is okay,
except for missing or definitely incompatible header files. Even then
it's up to the user to find the *real* problem, and to adjust his config
accordingly. He who can find out the trouble maker will also be capable
of correting the config accordingly, be with or without a GUI.
If you don't like my tools, then either improve them or don't use them.
I'm open to constructive criticism, but the implementation of your
suggestions is not as simple as you think. Instead you should understand
the real problems first, and how they could be solved in concrete code.
DoDi
More information about the fpc-devel
mailing list