I found that procedure pointers can't be compared if their types was declared separately:
MODULE A;
TYPE
Proc = PROCEDURE;
PROCEDURE Test1 (): BOOLEAN;
VAR
P1, P2: PROCEDURE;
BEGIN
RETURN P1 = P2; (* ok *)
END Test1;
PROCEDURE Test2 (): BOOLEAN;
VAR
P1: PROCEDURE;
P2: PROCEDURE;
BEGIN
RETURN P1 = P2; (* error *)
END Test2;
PROCEDURE Test3 (): BOOLEAN;
VAR
P1: Proc;
P2: Proc;
BEGIN
RETURN P1 = P2; (* ok *)
END Test3;
END A.
Is it possible to fix it?
Can't compare procedure pointers
- Ivan Denisov
- Posts: 362
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Krasnoyarsk, Russia
Re: Can't compare procedure pointers
Many Center members think, that it is not a bug but a feature...
http://forum.blackboxframework.org/view ... =460#p3962
So it should be some further discussion before decision to fix or not to fix.
http://forum.blackboxframework.org/view ... =460#p3962
So it should be some further discussion before decision to fix or not to fix.
-
- Posts: 262
- Joined: Tue Sep 17, 2013 6:50 am
Re: Can't compare procedure pointers
This is the intended behavior.
It gives you more control about what is compatible and what is not compatible.
A complex number, for example, could be represented using cartesian or polar coordinates.
Both have two REAL components but they are very different.
Structural equivalence would treat them as compatible, but name equivalence allows
you to make them two incompatible types.
- Josef
It gives you more control about what is compatible and what is not compatible.
A complex number, for example, could be represented using cartesian or polar coordinates.
Both have two REAL components but they are very different.
Structural equivalence would treat them as compatible, but name equivalence allows
you to make them two incompatible types.
- Josef
Re: Can't compare procedure pointers
I think that procedure and record are different types. In Component Pascal it is not possible to declare procedure with defined type.
Also it is possible to assign compatible procedure variables, but impossible to compare. That is inconsistent.
Also it is possible to assign compatible procedure variables, but impossible to compare. That is inconsistent.
Code: Select all
MODULE A;
TYPE
Proc1 = PROCEDURE (arg1: INTEGER);
Proc2 = PROCEDURE (arg2: INTEGER);
PROCEDURE Proc (arg: INTEGER);
BEGIN
END Proc;
PROCEDURE Do*;
VAR P1: Proc1; P2: Proc2;
BEGIN
P1 := Proc; (* ok *)
P2 := Proc; (* ok *)
P1 := P2; (* ok *)
ASSERT(P1 = P2); (* error *)
END Do;
END A.
Re: Can't compare procedure pointers
No, please read Josef's argument again.X512 wrote:I think that procedure and record are different types. In Component Pascal it is not possible to declare procedure with defined type.
Also it is possible to assign compatible procedure variables, but impossible to compare. That is inconsistent.
change
Code: Select all
PROCEDURE Do*;
VAR P1: Proc1; P2: Proc2;
BEGIN
Code: Select all
PROCEDURE Do*;
VAR P1: Proc1; P2: Proc1;
BEGIN
- Helmut
-
- Posts: 262
- Joined: Tue Sep 17, 2013 6:50 am
Re: Can't compare procedure pointers
Comparing a procedure variable with a procedure literal is not allowed indeed.
This is a limitation that is not directly related to the question of using name or structural equivalence because in this case only structural equivalence would work.
The reasons for this limitation may be that
(1) nobody ever needed it and that
(2) it reduces the usage of structural equivalence in the compiler to the assignment of procedures to procedure variables.
What do you need this comparison for?
- Josef
This is a limitation that is not directly related to the question of using name or structural equivalence because in this case only structural equivalence would work.
The reasons for this limitation may be that
(1) nobody ever needed it and that
(2) it reduces the usage of structural equivalence in the compiler to the assignment of procedures to procedure variables.
What do you need this comparison for?
- Josef
Re: Can't compare procedure pointers
I used procedure pointer comparison for registering and unregistering handlers defined by procedures, so handler can't be registered twice and handler can be unregistered by it's procedure pointer. This is used for "text as interface" pattern, handlers are defined by Module.Procedure in text. Currently problem is solved by defining procedure type for handler, but this is a bit annoying. Anyway this is not important problem.