Hello all,
A while back I forwarded a bit of extended Pascal code that I thought
should compile with gpc, but doesn't. This is example 1) below. gpc
complains that the identifier `I' is not declared and goes on to complain
about the comparison of I with 2 not being a boolean type.
I've been tinkering to see if I can figure out what is going on and found
that I can get the code to compile if I use the module-declaration =
module-heading[ `;' module-block] form rather than the module-declaration
= module-heading module-identification `;' module-block form. The
modified code from example 1) is given as example 2). This compiles
without warnings.
I couldn't find anything in the standard about when to use one form of
module and when to use the other, so I typed in some of the code examples
provided with the standard to see how gpc performs with (hopefully)
correct extended Pascal code. I discovered that gpc compiles almost
everything that I tried. It does not compile the example module
`generic-sort' that is given on pages 129-130 of the standard. For
convenience, I include this code as example 3). This code fails to
complile with message that `greater' and `swap' are undeclared
identifiers, which reminds me of the messages reported for example 1).
This module also uses the module-declaration = module-heading
module-identification `;' module-block form.
I suspect that I have found something that gpc does not do correctly, but
I am far from confident that my suspicion is correct. Here are my other
suspicions:
a) I don't have gpc built correctly. I had some problems getting gpc to
compile on my Linux box and can't really say what I did to make it
compile--that is which change really made a difference. Could I be having
problems with an incorrectly built gpc?
b) the code in examples 1) and 3) relies on a feature of extended Pascal
that gpc does not yet implement. I am relatively new to gpc and to
extended Pascal and can't answer this one myself. Does the code in
examples 1) and 3) fail because of an unimplemented feature of extended
Pascal?
Thanks for your help!
Tom
Thomas S. Dye, Ph.D.
Home: 813 16th Avenue, Honolulu, Hawaii 96816. Voice (808) 734-2087.
Work: International Archaeological Research Institute, Inc., 949 McCully St.,
Suite 5, Honolulu, Hawaii 96826. Voice (808) 946-2548; Fax 943-0716.
Example 1)
module charbug interface;
export
charbug = (IsAlphaNum);
function IsAlphaNum (ch : char; i : integer) : boolean;
end.
module charbug implementation;
function IsAlphaNum;
begin
if i > 2 then
IsAlphaNum:= ch in ['A'..'Z','a'..'z','0'..'9'];
end;
end.
Example 2)
module charbug;
export charbug = (IsAlphaNum);
function IsAlphaNum (ch : char; i : integer) : boolean;
end;
function IsAlphaNum;
begin
if i > 2 then
IsAlphaNum:= ch in ['A'..'Z','a'..'z','0'..'9'];
end;
end.
Example 3)
module generic_sort interface;
export generic_sort = (do_the_sort, max_sort_index,
protected current_pass => number_of_passes,
protected swap_occurred_during_sort);
type
max_sort_index = 1..maxint;
procedure do_the_sort(element_count : max_sort_index; function
greater(e1, e2 : max_sort_index) : boolean; procedure swap(e1,e2 :
max_sort_index) );
var
current_pass : 0..maxint value 0;
swap_occurred_during_sort : boolean value false;
end.
module generic_sort implementation;
procedure do_the_sort;
var
swap_occurred_this_pass : boolean;
n : max_sort_index;
begin
current_pass := 0;
swap_occurred_during_sort := false;
repeat
swap_occurred_this_pass := false;
current_pass := current_pass + 1;
for n := 1 to element_count - 1 do
if greater(n, n + 1) then begin
swap(n, n + 1);
swap_occurred_this_pass := true;
end;
swap_occurred_during_sort := swap_occurred_during_sort or swap_occurred_this_pass;
until not swap_occurred_this_pass;
end; { do_the_sort }
end.