Quote
ronka...@cc.helsinki.fi (Osmo Ronkanen) wrote:
>R.E.Donais <rdon...@southeast.net> wrote:
>>include the function or procedure header w/ the 2nd declaration?
>>If so, don't. If you wan't a copy of the header with the body
>>of the procedure then make it a comment.
>No, don't make it a comment. In fact one should put the parameters also
>in where the actual body is defined. That way the compiler can check
>that you have identical definitions on both giving extra security. The
>compiler does not check the comments.
You're right! Wasn't I surprised when it worked all the way
back to 1.0, and even with CP/M versions 1, 2, and 3! Count
this as the new thing I learned today. ;-)
The only reason I can see why I've never listed the formal
parameters with the body of a forward declared procedure is
because the fine manuals (both TP 1.0 and 3.0) state:
Forward References
A subprogram is forward declared by specifying its
heading separately from the block. This separate
subprogram heading is exactly as the normal heading,
except that it is terminated by the reserved word
forward. The block follows later within the same
declaration part. Notice that the block is initiated
by a copy of the heading, specifying only the name
and no parameters, types, etc.
Example:
program Catch22;
Var X: Integer;
function Up(Var I: Integer): Integer; forward;
function Down(Var I: Integer) : Integer;
begin
I := I div 2; Writeln(I);
if I <> 1 then I := Up(I);
end;
function Up;
begin
...
Seems I took the manual on blind faith, and since it worked, and
possibly because it's rarely used, I never took the opportunity
to experiment. Can't remember, but even if I used forward after
TP 3.0, it never appeared on a list of differences between
versions, so I would never have changed.
Guess I'm just a persistent old goat. :-)
Quote
>Do you also leave the parameters out of the procedures and functions
>that already are defined in the interface section of the unit?
Sometimes. Like when maintaining a multi-version unit and
finding its much easier to comment than have to type a bunch of
IFDEF's a second time - argh!
...red
--
Support the anti-Spam amendment
Join at http://www.cauce.org/