[comp.lang.pascal] Fragmented Declaration Blocks Legal?

beh@bu-pub.bu.edu (Bruce E. Howells) (08/02/89)

We're running ANSTO Pascal v3 here, and in an effort to cure some annoying
string errors, I've been looking at putting an "add-in" package of routines
to create the types, globals, and procedures I'll need.  Much to my dismay,
I found that the following construct is legal, and works "properly":

program ugh(output);
type type1= integer;
var var1: type1;
procedure proc1;
  begin
  writeln (' proc1');
  end;
(* now it gets interesting... *)
type type2=alfa; (* alfa is a built-in packed array [1..8] of char *)
var var2:type2;
procedure proc2;
  begin
  writeln (' proc2');
  end;
begin (* main *)
  writeln (' nothing');
end.

- The above was hand-written, so if it has a syntax error or two,
- my apologies...

Of course, this is just what I need to stick a bunch of code in there with
a single include (switching input to another file until eof) - but is it
really correct (or polite)?  It seems to go directly against what I know of Pascal, but
it's there...  Comments?

Bruce E Howells, beh@bu-pub.bu.edu / engnbsc@buacca.bitnet
  Just a lowly engineering undergrad at Boston University...

jourdan@seti.inria.fr (jourdan martin joseph) (08/18/89)

In article <35692@bu-cs.BU.EDU> beh@bu-pub.bu.edu (Bruce E. Howells) writes:
>
>We're running ANSTO Pascal v3 here, and in an effort to cure some annoying
>string errors, I've been looking at putting an "add-in" package of routines
>to create the types, globals, and procedures I'll need.  Much to my dismay,
>I found that the following construct is legal, and works "properly":
>
[I deleted the example program in which type, var and procedure
declarations were freely intermixed]
>
>Of course, this is just what I need to stick a bunch of code in there with
>a single include (switching input to another file until eof) - but is it
>really correct (or polite)?  It seems to go directly against what I know of Pascal, but
>it's there...  Comments?
>
>Bruce E Howells, beh@bu-pub.bu.edu / engnbsc@buacca.bitnet
>  Just a lowly engineering undergrad at Boston University...

Allowing free intermixion of several declaration parts (I mean "type",
"const", "var", "procedure", etc.) is one of the most common
extensions to Standard Pascal.  This, as you discovered, is to ease
the inclusion of complete related set of declarations, mainly for
separate compilation.  So use it if your compiler allows it.

BTW, I remember an old implementation of Pascal which allowed file
inclusion but forbade multiple/intermixed declaration parts.  This was
a mess because it forced you to split a set of related declarations
into several files...

Also, keep in mind that everything related to separate compilation
(including the matters discussed above) is NOT Standard Pascal, so
beware if you want to write portable code.  It's certainly allowed (in
one form or another) in the new ISO Extended Pascal Standard.
-- 

Martin Jourdan <jourdan@minos.inria.fr>, INRIA, Rocquencourt, France.
My employers have no opinion and they guarantee my freedom of expression.