Syntax question, PASCAL vs. C

G

gwlemyre

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.
 
J

Jens Marder

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.
 
J

Jens.Toerring

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top