Hi all,
It seems that operators pow and ** cannot be redefined in gpc. Is that expected ?
I work with djgpp / w98 dos box (should be irrelevant I think)
Thanks
Maurice
Maurice Lombardi wrote:
Hi all,
It seems that operators pow and ** cannot be redefined in gpc. Is that expected ?
No, they should be. I think adding them in parse.y:operator_identifier should do the trick, but there's a comment stating exactly that this "is unnecessary". Seems it is necessary, but since I don't know the real meaning of this comment, I'll leave this to Peter... (maur7.pas)
Frank
Frank Heckenbach a écrit :
Maurice Lombardi wrote:
It seems that operators pow and ** cannot be redefined in gpc. Is that expected ?
No, they should be. I think adding them in parse.y:operator_identifier should do the trick, but there's a comment stating exactly that this "is unnecessary". Seems it is necessary, but since I don't know the real meaning of this comment, I'll leave this to Peter... (maur7.pas)
With today snapshot (20001214) pow and shl work as expected, but ** compiles but fails when using it with a message:
operatordemo.pas: In function `pascal_main_program': operatordemo.pas:49: left operand of `**' must be of integer, real or complex type
The test program is just an expansion of operatordemo:
------------------------------------------------------ program OperatorDemo;
type Vector3 = record x, y, z: Real; end;
var a, b, c: Vector3 = (1, 2, 3);
operator + (u, v: Vector3) w: Vector3; begin w.x := u.x + v.x; w.y := u.y + v.y; w.z := u.z + v.z; end;
operator pow (u: Vector3; v: integer) w: Vector3; begin w.x := u.x pow v; w.y := u.y pow v; w.z := u.z pow v; end;
operator shl (u: Vector3; v:integer) w: Vector3; begin w.x := round(u.x) shl v; w.y := round(u.y) shl v; w.z := round(u.z) shl v; end;
operator ** (u: Vector3; v:real) w: Vector3; begin w.x := u.x ** v; w.y := u.y ** v; w.z := u.z ** v; end;
begin c := a + b ; writeln(c.x,' ',c.y,' ',c.z);
c := a pow 3; writeln(c.x,' ',c.y,' ',c.z);
c := a shl 2; writeln(c.x,' ',c.y,' ',c.z);
c := a ** 2.5; (* WRONG *) writeln(c.x,' ',c.y,' ',c.z);
readln;
end. ------------------------------------------------
Hope this helps
Maurice
Hi, Maurice!
I'll leave this to Peter... (maur7.pas)
With today snapshot (20001214) pow and shl work as expected, but ** compiles but fails when using it with a message:
operatordemo.pas: In function `pascal_main_program': operatordemo.pas:49: left operand of `**' must be of integer, real or complex type
Indeed - I wanted to fix this too before announcing anything to the list, but you were faster. ;-)
The problem is that `pow' and `**' share a single tree node, so they cannot be distinguished in a simple way when it comes to redefinition of operators.
Peter
Something is broken on the list right now. Nobody can write ten messages per minute, especially dated from any day since more than one year from now.
Please somebody in charge do something, quick! All our mailboxes will overflow soon with messages from levi@localhost.nc3a.nato.int
Olivier Lecarme