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 7 of 16 Topic 187 of 215
Post > Topic >>

Re: function as a pointer.

by Waldek Hebisch <hebisch@[EMAIL PROTECTED] > Dec 14, 2006 at 07:24 PM

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.  

> myfun:=nil;

Legal, but since the assignment destroys previous value it is probably
not what you want.

> ...
> end;
> 
> and so on...
> I understand that name of the function is seen as variable inside this
> function...
>

No, name of the function works as variable if it is the only thing
on the left hand side of the assignment statement.  Otherwise 
name of the function means (possibly malformed) recursive call.

So, to allocate memory inside myfun you need an extra variable.
 
> so if i modify it inside the function... the function will return it
> (there is no such a thing as 'return')... and it won't be distroyed
> after execution of my function.
> 
> so that i could write:
> var
> ohyeah:pnode;
> begin
> ohyeah:=myfun();
> 

either:

ohyeah:=myfun;

or

ohyeah:=myfun(...);

(if a function has no parameters ANSI/ISO does not allow empty
parentheses).

-- 
                              Waldek Hebisch
hebisch@[EMAIL PROTECTED]

 




 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 Wed Jul 23 16:07:07 CDT 2008.