Syntax question, PASCAL vs. C

Discussion in 'C Programming' started by gwlemyre@earthlink.net, Feb 9, 2005.

  1. Guest

    I am not a PASCAL programmer and I saw this piece of code.

    procedure Expression; Forward;
    procedure Factor;
    begin
    if Look = '(' then begin
    Match('(');
    Expression;
    Match(')');
    end
    else
    EmitLn('MOVE #' + GetNum + ',D0');
    end;

    Is it valid? In particular, why are there two "procedure" statements?
    Why does one of them have two names?

    If it is valid, what is the C equivalent?

    Thanks in advance.
     
    , Feb 9, 2005
    #1
    1. Advertising

  2. Jens Marder Guest

    No two names.
    As stated, it's a "forward declaration".
    Meaning, procedure Expression isn't defined at this moment
    in the source code, so the name and the interface of the proc
    have to be declared, so that the call to Expression in the
    if-block doesn't cause a compiler error.
    "Same procedure" as in C.

    <> schrieb im Newsbeitrag
    news:...
    >I am not a PASCAL programmer and I saw this piece of code.
    >
    > procedure Expression; Forward;
    > procedure Factor;
    > begin
    > if Look = '(' then begin
    > Match('(');
    > Expression;
    > Match(')');
    > end
    > else
    > EmitLn('MOVE #' + GetNum + ',D0');
    > end;
    >
    > Is it valid? In particular, why are there two "procedure" statements?
    > Why does one of them have two names?
    >
    > If it is valid, what is the C equivalent?
    >
    > Thanks in advance.
    >
     
    Jens Marder, Feb 9, 2005
    #2
    1. Advertising

  3. -berlin.de Guest

    wrote:
    > I am not a PASCAL programmer and I saw this piece of code.


    > procedure Expression; Forward;
    > procedure Factor;
    > begin
    > if Look = '(' then begin
    > Match('(');
    > Expression;
    > Match(')');
    > end
    > else
    > EmitLn('MOVE #' + GetNum + ',D0');
    > end;


    > Is it valid? In particular, why are there two "procedure" statements?
    > Why does one of them have two names?


    A quick google search with "Pascal+Forward" would show you what it
    does: it tells the compiler that there's a function to be defined
    later, but which needs to be used already before its definition has
    been seen by the compiler, see e.g.

    http://www.taoyue.com/tutorials/pascal/pas4f.html

    (I don't remember how case-sensitive Pascal is and if "Forward"
    doesn't need to be spelt "forward".)

    > If it is valid, what is the C equivalent?


    It's exactly the same like in Pascal, a simple declaration of a
    function before its definition like in

    void B( void );

    void A( void ) {
    B( );
    printf( "See, we used B() before its definition.\n" );
    }

    void B( void )
    printf( "Hello world\n" );
    }
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
     
    -berlin.de, Feb 9, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam

    Pascal-style "types"

    Adam, Feb 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    346
  2. Ivan Vecerina
    Replies:
    1
    Views:
    1,249
    Jerry Coffin
    Oct 21, 2003
  3. Jeff Schwab

    Translating from C to Pascal

    Jeff Schwab, Dec 31, 2003, in forum: C++
    Replies:
    10
    Views:
    690
    Jeff Schwab
    Jan 1, 2004
  4. Chris Gordon-Smith

    Calling Pascal from C++ and Vice Versa

    Chris Gordon-Smith, Jan 17, 2004, in forum: C++
    Replies:
    4
    Views:
    2,970
    EventHelix.com
    Jan 18, 2004
  5. robert
    Replies:
    0
    Views:
    328
    robert
    Oct 26, 2006
Loading...

Share This Page