Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Function/Subroutine overloading???

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 27 January 2006, 20:32 PM    Post subject: Function/Subroutine overloading??? Reply with quote

Does ZBasic support function/subroutine overloading. I get that impression when
I read the System Library documentation. For example:

GetQueue(queue, var, count) or
GetQueue(queue, var, count, timeLimit, timeoutFlag)

Same subroutine, different paramenter list.

Cam this sort of thing be done with my ZBasic functions/subroutines as well? If so, what are the rules?

Here is a similar example from the Delphi7 help file as well along with the explanation.
I expect C++ allows this as well.

Note that Delphi requires the use of the overload directive.
Code:

function Divide(X, Y: Real): Real; overload;
begin
  Result := X/Y;
end;
function Divide(X, Y: Integer): Integer; overload;
begin
  Result := X div Y;
end;


These declarations create two functions, both called Divide, that take parameters of
different types. When you call Divide, the compiler determines which function to invoke
by looking at the actual parameters passed in the call. For example, Divide(6.0, 3.0)
calls the first Divide function, because its arguments are real-valued.

In the Delphi case, the routines must be different in their calling sequence either
by parameter type or number.

Any enlightenment will be appreciated.

Vic
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 27 January 2006, 21:02 PM    Post subject: Reply with quote

Yes the compiler supports polymorphism (function overloading) but only for system library functions. The classic example is CStr which can take a variety of types as the parameter.

This support was added I believe because it is compatible with BasciX and is also nice for application developers. Adding generic support for user written polymorphic functions would be a great addition but would add significant code/effort in the compiler.
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 661

Posted: 28 January 2006, 0:44 AM    Post subject: Reply with quote

In C++, and I suppose in other languages as well, these "overloaded" functions do not really have the same name. In English they have the same name, but to the compiler, one is "the function beginning at address xxxx:xxxx", and the other is the "function beginning at address yyyy:yyyy".

It is a fictional name that seems to you to be the "same".

So, you can have FunctionI() for integer args, FunctionF() for floats, FunctionB() for byte args, and so on. You save the compiler developer many headaches, You still have to know by what types of args you need to pass, which letter to append to the function name. It uses no more space than overloaded functions (since I do not know the exact specific inside compilers, I will amend that statment to read "little more space".)

I have written certain user functions like this for BasicX and ZBasic for a while now. I have not written much in C++ for 15 years, and I really do not miss much of the C++ syntax, except a couple of basic pointer niceties.

Vic, Is there something you really need that polymorphism for that would be very inconvenient to rewrite as FunctionI(), FunctionB(), etc? I admit, that I did write a few polymorphic functions here and there and it was cool!

-Tony
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group