Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Ansi -iso > Re: function as...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 9 of 16 Topic 187 of 215
Post > Topic >>

Re: function as a pointer.

by scott moore <nospam@[EMAIL PROTECTED] > Dec 16, 2006 at 09:55 AM

This runs via IP as:

==========================================================================
program test;

type pnode = ^integer;

function myfun : pnode;

begin

    new(myfun);
    myfun:=nil;

end;

begin
end.

C:\TEST>parse test
Pascal parser vs. 1.13.05 Copyright (C) 2005 S. A. Moore
Processing: C:\TEST\test.pas
    new(myfun);
              ^
*** C:\TEST\test.pas [9:14] 'myfun' must be a variable type ***
Errors this compilation: 1
No output file was generated
Function complete

==========================================================================

The function definitely isn't defined as a variable in it's body. The
only valid reference to it is the last statement, myfun := nil, which
is not, in fact, an assignment, but rather the establishment of a
function result (for myfun). Although logically treating the function
result as a "write only" variable is one implementation solution,
there are many others. In fact, reduction to a single register is a
reasonable optimization, and that, in and of itself implies that
promoting function results to variables in attempts to achieve
artificial orthogonality is unwise.

In any case, no, this does not comply with ISO 7185.

John Reagan wrote:
> Waldek Hebisch wrote:
>> steelman22 <steelman22@[EMAIL PROTECTED]
> wrote:
>>
>>> I have a function
>>>
>>> function myfun(....) : pnode {pnode is pointer}
>>> ..
>>> is it ok to do this thing:
>>>
>>> function myfun(....) : pnode
>>> begin
>>> ...
>>> new(myfun);
>>
>>       ^^^^^
>> According to ANSI/ISO this is a recursive call. 
> 
> Not in my ANSI/ISO standard it isn't.
> 
> The parameter for NEW isn't an expression but a variable-access.
> 
> Variable-access is defined as
> 
> variable-access = entire-variable | component-variable | 
> identified-variable | buffer-variable.
> 
> So you can't get to function-call.
> 
> 
> However, doing "new(myfun)" still isn't legal since function-idenitifer 
> isn't part of variable-access.  The standard says there must be at least

> one assignment-statement to the function-identifier in the 
> closest-containing block.
> 
> Any compiler that accepts "new(myfun)" is doing so as an exception.  My 
> compiler signals an error:
> 
> $ pascal xxx
> 
>  new(p);
> .....^
> %PASCAL-E-IVUSEFNID, Illegal use of function identifier P
> at line number 7 in file HIYALL$:[REAGAN]XXX.PAS;1
> %PASCAL-E-ENDDIAGS, PASCAL completed with 1 diagnostic
> 
> 
>
 




 16 Posts in Topic:
function as a pointer.
"steelman22" &l  2006-12-13 12:50:35 
Re: function as a pointer.
"Chris Burrows"  2006-12-14 12:18:26 
Re: function as a pointer.
CBFalconer <cbfalconer  2006-12-13 21:45:35 
Re: function as a pointer.
"Chris Burrows"  2006-12-14 14:50:51 
Re: function as a pointer.
John Reagan <john.reag  2006-12-14 15:10:25 
Re: function as a pointer.
CBFalconer <cbfalconer  2006-12-13 20:22:40 
Re: function as a pointer.
Waldek Hebisch <hebisc  2006-12-14 19:24:48 
Re: function as a pointer.
John Reagan <john.reag  2006-12-15 16:49:02 
Re: function as a pointer.
scott moore <nospam@[E  2006-12-16 09:55:57 
Re: function as a pointer.
John Reagan <john.reag  2006-12-20 00:45:08 
Re: function as a pointer.
scott moore <nospam@[E  2006-12-20 10:13:07 
Re: function as a pointer.
"Chris Burrows"  2006-12-21 09:55:38 
Re: function as a pointer.
CBFalconer <cbfalconer  2006-12-20 23:26:40 
Re: function as a pointer.
John Reagan <john.reag  2007-01-02 15:21:12 
Re: function as a pointer.
scott moore <nospam@[E  2007-01-02 07:59:18 
Re: Standards Committees (was: function as a pointer).
"Chris Burrows"  2007-01-03 10:01:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 5:41:37 CDT 2008.