Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: How do you translate from C++ to Pascal ?

  1. #11

    How do you translate from C++ to Pascal ?

    I've never actually tried this myself, but just an idea: wouldn't it be helpful if you, first, let C/C++ preprocessor do the job, and apply C->Pascal translator on the result of it? Of course, you will loose any important #ifdef's (for example those conserning OS or CPU used), but you wouldn't need to worry about macro-hell. Looking at your example, I'm pretty sure it would do the job
    blog: http://alexionne.blogspot.com/

  2. #12

    How do you translate from C++ to Pascal ?

    Quote Originally Posted by Legolas
    Quote Originally Posted by Zampoteh
    Quote Originally Posted by Robert Kosek
    Yes. Do not use an automatic translator/interpreter. On rare occasion they work well, but they almost never generate human readable code (Note that I do not consider C/C++ as human readable ) if they do function.

    The best way is to just do all the footwork yourself.
    But how to do it without mistakes?
    For example. I want to translate function
    327 int dBoxBox
    http://opende.svn.sourceforge.net/vi...87&view=markup
    It is big and used many macroses.

    And sometimes we really doesn't need to know how any function work. We just want to get a fast result.
    YAY! That's huge, ugly and scary! First of all: put all these macros out of your function and translate it as pascal procedures.
    I don't know how to do it without mistakes.
    How to find one small mistake in that heap of macroses? If i did it?

    I tried to translate them with C2PAS32.EXE. But it doesn't know how to translate some of them too.

  3. #13

    How do you translate from C++ to Pascal ?

    For example
    ?ë++
    Code:
    #define dMULTIPLYOP0_331(A,op,B,C) \
    do { \
      (A)[0] op dDOT((B),(C)); \
      (A)[1] op dDOT((B+4),(C)); \
      (A)[2] op dDOT((B+8),(C)); \
    } while(0)
    
    DECL dMULTIPLY0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,=,B,C); }
    
    DECL dMULTIPLYADD0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,+=,B,C); }
    C2PAS32.EXE
    Code:
    function dMULTIPLYOP0_331(A: integer; op: integer; B: integer; C: integer): integer; 
    begin
      result:= do((A)[0]opdDOT((B),(C));(A)[1]opdDOT((B+4),(C));(A)[2]opdDOT((B+8),(C));)while(0)
    end;
    http://opende.svn.sourceforge.net/vi...41&view=markup

  4. #14

    How do you translate from C++ to Pascal ?

    Code:
    #define dMULTIPLYOP0_331(A,op,B,C) \
    do { \
      (A)[0] op dDOT((B),(C)); \
      (A)[1] op dDOT((B+4),(C)); \
      (A)[2] op dDOT((B+8),(C)); \
    } while(0)
    
    DECL dMULTIPLY0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,=,B,C); }
    
    DECL dMULTIPLYADD0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,+=,B,C); }
    The dMULTIPLYOP0_331 can't be translated to Pascal because it's an "expression builder". The "op" parameter means an operator and the result is an expression that should be compilled. I mean, when C compiles
    Code:
    DECL dMULTIPLY0_331(TA *A, const TB *B, const TC *C) { dMULTIPLYOP0_331(A,=,B,C); }
    the preprocessor returns:
    Code:
    extern pascal void dMULTIPLY0_331 (int *A, const int *B, const int *C)
    {
      do {
       (A)[0] = dDOT((B),(C));
       (A)[1] = dDOT((B+4),(C));
       (A)[2] = dDOT((B+8),(C));
      } while(0)
    }
    AFAIK it's not possible to do it in Pascal. You must "unroll" those macros by hand to translate it to Pascal.
    No signature provided yet.

  5. #15

    How do you translate from C++ to Pascal ?

    Quote Originally Posted by ?ëu?±o Mart??nez
    AFAIK it's not possible to do it in Pascal. You must "unroll" those macros by hand to translate it to Pascal.
    FreePascal supports macros, but I have not used them so can't comment further on them.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  6. #16

    How do you translate from C++ to Pascal ?

    http://cc.codegear.com/Item.aspx?id=23991

    C to Pascal conversion util.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •