I have changed from gpc into turbo pascal. The code that compiled for me in gpc doesnt compile now in turbo pascal. The code:
type NumNode = record Value: integer; pNext: ^ NumNode; end;
The compile error I get: Undefined type in pointer definition (NUMNODE)
__________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new resources site! http://smallbusiness.yahoo.com/resources/
loop lopy wrote:
I have changed from gpc into turbo pascal. The code that compiled for me in gpc doesnt compile now in turbo pascal. The code:
type NumNode = record Value: integer; pNext: ^ NumNode; end;
The compile error I get: Undefined type in pointer definition (NUMNODE)
Apart from the fact that TP can't compile Pascal, that shouldn't compile anywhere. You can't use NumNode until it is defined, and it isn't defined until the "end;" is encountered. Except to forward define a pointer type. Thus you need:
TYPE NumNodePtr = ^NumNode;
NumNode = RECORD Value : integer; pNext : NumNodePtr; END;
Get a Pascal book.
CBFalconer wrote:
loop lopy wrote:
I have changed from gpc into turbo pascal. The code that compiled for me in gpc doesnt compile now in turbo pascal. The code:
type NumNode = record Value: integer; pNext: ^ NumNode; end;
The compile error I get: Undefined type in pointer definition (NUMNODE)
Apart from the fact that TP can't compile Pascal, that shouldn't compile anywhere. You can't use NumNode until it is defined, and it isn't defined until the "end;" is encountered. Except to forward define a pointer type. Thus you need: Get a Pascal book.
AFAICS code written by loopy is perfectly legal standard pascal. Granted, it is unusual since the type of field `pNext' is incompatible with any other type, so you can not create a plain variable of the same type. But it seems that:
var head: NumNode; begin new(head.pNext) end
is legal iso7185. And Pascal P4 and Stanford Pascal both accept the program.
BTW, gpc, Pascal P4 and Stanford Pascal allow the following (illegal) code:
var head: numnode; pnode: ^ numnode;
begin new(pnode); head.pnext := pnode {illegal, types do not match} end .
Given original declaration it is tempting to write the code above which is indeed illegal. But no reason to reject original declaration.
Waldek Hebisch wrote:
CBFalconer wrote:
loop lopy wrote:
I have changed from gpc into turbo pascal. The code that compiled for me in gpc doesnt compile now in turbo pascal. The code:
type NumNode = record Value: integer; pNext: ^ NumNode; end;
The compile error I get: Undefined type in pointer definition (NUMNODE)
Apart from the fact that TP can't compile Pascal, that shouldn't compile anywhere. You can't use NumNode until it is defined, and it isn't defined until the "end;" is encountered. Except to forward define a pointer type. Thus you need: Get a Pascal book.
AFAICS code written by loopy is perfectly legal standard pascal.
I agree (and GPC accepts it).
BTW, gpc, Pascal P4 and Stanford Pascal allow the following (illegal) code:
Yes, we've already discussed that GPC's type checking is not quite correct (mostly, it's too lax with pointer types AFAIK). If you want to improve it (as you mentioned once), just go ahead -- I probably won't get to that area soon.
Frank