No announcement yet.

Tools to aid in converting C to PowerBASIC

  • Filter
  • Time
  • Show
Clear All
new posts

  • Tools to aid in converting C to PowerBASIC

    (1). C preprocessor (header files. macros, etc.)

    Walter Bright authors C family compilers (free) under the Digital Mars brand.

    Of specific interest, Walter has the Digital Mars C compiler and Digital Mars D compiler. D is Walter's vision of what C++ should have been - a, from the ground, up, total rework of C.

    Anyway, although D is highly similar (syntactically) to C, it is not backwards compatible and does not compile C code. So Walter has guidelines on converting from C to D.

    Those guidelines, specifically the page on "Converting C .h Files to D Modules" are one piece of converting C code to PowerBASIC. Since D doesn't use the C .h header files, C macros, etc., Walter has us use his C compiler to create a new version of the source file in which all the text preprocessing has taken place (macros expanded, etc.). What is our number one problem with conversion? "What does this C macro mean?" - Voila! - All of the C preprocessor garbage is converted to standard C code for us.

    Note: Much of the D Language part of the website is useful to a PowerBASIC programmer trying to convert C code. Walter has gone in-depth to justify his reasoning for "why D?". In doing so, he has had to explain everything that C does wrong. Which means that we PowerBASIC programmers have a resource that explains almost everything that C DOES!!!

    (2). C to PowerBASIC

    Ok - The main problems we face here are - a. figuring out what a piece of C code is doing - b. figuring out structures, parameters, etc.

    The tool for this job is a C interpreter (free - standard version) called Ch . If you are a student, simply go download the professional version for free (it has a much better IDE)

    Ch will do everything from run a single C statement to an entire C program - (it handles a lot of C++ also). Since it's an interpreter, it's very easy to inspect and change values.

    The other day, a colleague of mine figured out how to use SQLite (in C) by playing with it in Ch until he knew what all of the calls that he needed did. That would also be the first step you would when porting SQLite's C interface to PowerBASIC.

    (3). C to ASM (for the mentally unstable among us)

    Walter Bright's "OBJ2ASM: Object File Disassembler" comes in handy for this.


    I am not an expert at this. I just had to do a small conversion a few weeks ago and I was successful using the Digital Mars C compiler preprocessing directive and the Ch interpreter to figure out what the code was doing.

    Hope it helps,
    Bruce Huber

    aol.[hint - it's not "org"]

  • #2
    Interesting. When I can make some time, I might want to revisit this. It really sounds promising.


    • #3
      Thanks for the lead on this Bruce. I have brought down the Professional version ( some 36mB ) and find it to be a very good package. There is much to explore with examples and documentation. The IDE is quite intuitive and I would recommend adding this package to any of us interested in the persuit of knowledge.



      • #4
        Originally posted by Bruce Huber View Post
        That would also be the first step you would when porting SQLite's C interface to PowerBASIC.
        Jose Roca has done it for SQLite 3.5.6. SQLite's now at 3.5.9. See the following link:

        Thanks for the very interesting links in your post.


        • #5
          I update these headers regularly. This is the link for SQLite 3.5.9.

          Last edited by José Roca; 24 May 2008, 11:54 AM.