Pascal pointer to pointer SyntaxError and Incompatible types

喜夏-厌秋 提交于 2019-12-13 08:27:49

问题


Since there's no way to create refereces (is there?) I have to do it with a pointer to another pointer. This gives me an error:

type
  PNode = ^TNode;
  TNode = record
    char: char;
    next: PNode;
    children: PNode;
  end;

  PPNode = ^PNode; 
var
    current_node: PPNode;  
function find_or_insert_peer(var node: PNode; character: char): PNode; 

current_node := @find_or_insert_peer(current_node^, character)^.children;

x.pas(121,23) Error: Incompatible types: got "<address of function(var PNode;Char):^TNode;Register>" expected "PPNode"
x.pas(121,43) Fatal: Syntax error, ";" expected but "(" found
Fatal: Compilation aborted

I also tried this but it does not compile because of SyntaxError

current_node := @(find_or_insert_peer(current_node^, character)^.children);

Edit

Please help. I've even created a demo in c++ to show you this is legal. http://cpp.sh/8mxe


回答1:


As mentioned in a witty-called article "Addressing pointers" linked in comments the @ operator might not work properly with more complex expressions. Its equivalent addr() will do the trick.

current_node := addr(find_or_insert_peer(current_node^, character)^.children);


来源:https://stackoverflow.com/questions/41399595/pascal-pointer-to-pointer-syntaxerror-and-incompatible-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!