What facilities does GPC have for forward defining types.
In CW Pascal, I have some code that looks like this:
type
MyProc = procedure( browser: MyObjectA );
MyObjectA = object
f: MyProc;
b: MyObjectB;
procedure Doit( proc: MyProc );
function GetB: MyObjectB;
end;
MyObjectB = object;
f: MyObjectA;
// other references to ObjectA
end;
Keep in mind all the "used before defined" types are pointer types
(objects being implicitly pointers) and defined in the same "type"
block.
GPC is not happy with this. Needless to say, given the dual
referential nature of the references, it is hard to see how I can
cleanly untangle this.
Is there any support in GPC or EP for these kinds of forward defined
types? Any suggestions how I can untangle them within GPC?
The best I can see is to turn all of them into explicit pointers and
explicit dereferences, which is doable, but rather ugly.
Any suggestions?
Thanks,
Peter.
--
<http://www.stairways.com/> <http://download.stairways.com/>
At 13:09 +0200 5/7/05, Marco van de Voort wrote:
>In gmane.comp.compilers.gpc, you wrote:
>> What facilities does GPC have for forward defining types.
>>
>> In CW Pascal, I have some code that looks like this:
>[...]
>> MyObjectB = object;
>> f: MyObjectA;
>> // other references to ObjectA
>> end;
>
>(btw Does this compile? Note the semi-colon after object)
No, sorry, it was only meant as a basic idea, I didn't actually run
it through the compiler to get out any silly syntax errors like that.
>Delphi supports this: (remember its object model is similar)
>
>Type
> MyObjectB = class;
> MyObjectA = class;
> MyProc = procedure( browser: MyObjectA );
> MyObjectA = class
> f: MyProc;
> b: MyObjectB;
> procedure Doit( proc: MyProc );
> function GetB: MyObjectB;
> end;
> MyObjectB = class
> f: MyObjectA;
> // other references to ObjectA
> end;
>
>Must be in one typeblock though, IOW, the same system as pointers.
>For MacPascal mode object=class btw.
Yes, that would be what I'd expect, although the EP definition of
class .. end; is acceptable to.
I'd suggest GPC accept either syntax to be compatible with Delph and
EP (as well as allowing it with "object" when using reference objects
for the Mac case).
Enjoy,
Peter.
--
<http://www.stairways.com/> <http://download.stairways.com/>
marcov(a)stack.nl wrote:
> In gmane.comp.compilers.gpc, you wrote:
> > What facilities does GPC have for forward defining types.
> >
> > In CW Pascal, I have some code that looks like this:
> [...]
> > MyObjectB = object;
> > f: MyObjectA;
> > // other references to ObjectA
> > end;
>
> (btw Does this compile? Note the semi-colon after object)
Yes, the semicolon seems wrong (at least in other dialects).
> Delphi supports this: (remember its object model is similar)
>
> Type
> MyObjectB = class;
> MyObjectA = class;
This seems to be what `class .. end' is in OOE.
> Must be in one typeblock though, IOW, the same system as pointers.
Yes, same in OOE.
Frank
--
Frank Heckenbach, frank(a)g-n-u.de
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)
Good morning,
it's a while now that the binaries and sources are not available from GPC's
website. If one wants to download and install the latest stable version, how
should he/she do?
Thanks and regards
Silvio a Beccara
University of Trieste - Italy
--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f
Sponsor:
Scopri come proteggere dai virus il tuo computer e come eliminare
* ogni tipo di virus! - clicca qui
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=3212&d=5-7
The warning message for $D is:
ignoring BP directive `{$d-}' which is unnecessary in GPC
CW Pascal uses $D to turn symbol generation on and off (typically
used to disable around sensitive areas of code like password / serial
number / authentication / etc).
I don't know if there is any equivalent for the Mac directive, but
the warning is a bit inaccurate for Mac. Perhaps it should just be
the normal "unknown directive", or perhaps there should be a general
scheme for setting ignored directives (which could include $D for BP,
and could include $unused for Mac).
Or perhaps the warning message should just be changed a little?
Enjoy,
Peter.
--
<http://www.stairways.com/> <http://download.stairways.com/>
GPC accepts the following program, but produces quite silly results:
program Foo;
var
a: array [1 .. 2] of Integer value (0, 0);
i: Integer;
begin
i := 1;
for a[i] := 1 to 10 do
begin
WriteLn (i, ' ', a[i]);
if a[i] = 5 then i := 2
end
end.
The problem is that it evaluates the index i each time, not once
before the loop. It would be possible to fix it, but do we really
want that? Neither BP nor CP/EP allow it, they allow only
identifiers in for-loops.
Waldek and I see no need for such a feature. (If it made it possible
to nest a compile-time-unknown number of `for' loops, I could see
some point, but of course, it doesn't.)
So, would anybody mind dropping this misfeature, and requiring an
identifier in for-loop counters?
The same (and probably a lot of other weird stuff) can be achieved
with "extended" `absolute' variables, such as:
program Foo;
var
a: array [1 .. 2] of Integer value (0, 0);
i: Integer;
{$local W-} c: Integer absolute a[i]; {$endlocal}
begin
i := 1;
for c := 1 to 10 do
begin
WriteLn (i, ' ', c);
if a[i] = 5 then i := 2
end
end.
We support `absolute' for BP compatibility, but IMHO then we should
restrict it to what BP requires, i.e. really absolute addresses, or
the address of entire variables or parameters.
I suppose (hope) few users actually knew about the extended
(mis)features GPC allowed, so I hope we can drop them. (If not, we
probably should change semantics to evaluate the address once, and
not on each usage, as is done now, so if you rely on this behaviour,
you might have to change your code anyway -- if nothing else helps,
you can always achieve the same effect with type-casting of
pointers.) BP compatible code will not be affected.
Any objections?
Frank
--
Frank Heckenbach, frank(a)g-n-u.de
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)