Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Function Overloading

Reply
Thread Tools

Function Overloading

 
 
Malcolm
Guest
Posts: n/a
 
      10-05-2003

<(E-Mail Removed)> wrote in message
>
> > IMO you think wrong. A C++ function overload *is*
> > a function with a different name. C++ simply
> > 'hides' this fact.

>
> Yes, but in doing so it takes up some extra steps which in turn results in
> comparatively slower execution and more memory. Overloaded
> function resolution is not as simple as the programmer himself naming
> the functions differently.
>
> It compensates this by features such as dynamic binding and hence may >

load the function into memory only when required.
>
> BTW do the latest C compilers use dynamic binding?
>

C++ allows this

double root(double x);
double root(Quaternion q);

so you can take the root of a real or a quaternion using natural function
names. The C++ compiler will implement this by producing two functions with
mangled names, eg root_d and root_Quaternion. There is no runtime penalty
compared with writning two C functions with slightly different names.

However C++ also allows this

class number
{
public:
virtual void root(void) = 0;
};

Now we can declare "real" and "quaternion" as objects of type "number", and
provide for each a routine to reduce them to a square root.

The program decides what type "number" is a run time, and accesses the
function "root" through a pointer. There is therefore a speed and time
penalty compared with providing two directly-called C functions, though of
course the ability to use object-oriented design arguably compensates for
this.

Some platforms also put commonly-used library functions in separate modules
from the main executable. The OS may provide some sort of intelligent
management by only loading those functions which are needed at the time.
This has nothing to do with run-time binding in the C++ sense.

To answer the last question, you would have to clarify in what sense you are
using the term "dynamic binding".


 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      10-05-2003
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> On 6-Oct-2003, "Mike Wahler" <(E-Mail Removed)> wrote:
>
> > <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > >
> > > On 4-Oct-2003, Sheldon Simms <(E-Mail Removed)> wrote:
> > >
> > > > On Sat, 04 Oct 2003 10:59:35 +0000, http://www.velocityreviews.com/forums/(E-Mail Removed)lid wrote:
> > > >
> > > > >
> > > > > On 4-Oct-2003, "James Harris" <no.email.please> wrote:
> > > > >
> > > > >> "Ben Pfaff" <(E-Mail Removed)> wrote in message
> > > > >> news:(E-Mail Removed)...
> > > > >> > kelvSYC <(E-Mail Removed)> writes:
> > > > >> >
> > > > >> > > In C, can you make functions like this:
> > > > >> > >
> > > > >> > > int foo(int a);
> > > > >> > > int foo(int a, char b);
> > > > >> >
> > > > >> > No.
> > > > >>
> > > > >> Sadly not! ......
> > > > >
> > > > > It has it's own advantages and disadvantages. C code turns out to
> > > > > make
> > > > > smaller and more efficient executables when compared with C++,
> > > > > right?
> > > >
> > > > if so, then it's not because C lacks overloading of function names.
> > >
> > > I think overloading of functions *does* take up some extra memory when
> > > compared
> > > to using 2 functions with different names.

> >
> > IMO you think wrong. A C++ function overload *is*
> > a function with a different name. C++ simply
> > 'hides' this fact.

>
> Yes, but in doing so it takes up some extra steps which in turn results in
> comparatively slower execution and more memory. Overloaded function
> resolution is not as simple as the programmer himself naming the functions
> differently.


Overload resolution normally takes place at compile time, not
runtime.

> It compensates this by features such as dynamic binding and hence may load
> the function into memory only when required.


Dynamic binding has nothing to do with function overloading.

> BTW do the latest C compilers use dynamic binding?


No.

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


Would you please cut it out with the 20-plus blank lines at the
end of every article?
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-06-2003
Ben Pfaff <(E-Mail Removed)> scribbled the following:
> Would you please cut it out with the 20-plus blank lines at the
> end of every article?


But Ben! I have a 6-line signature! Surely that gives everyone else the
right to do whatever they want to?

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
- Guardian in "Jinxter"
 
Reply With Quote
 
no@no.invalid
Guest
Posts: n/a
 
      10-06-2003

On 6-Oct-2003, Ben Pfaff <(E-Mail Removed)> wrote:

> Would you please cut it out with the 20-plus blank lines at the
> end of every article?


Why don't you object those who use OE and break quotes instead?

 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      10-06-2003
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> On 6-Oct-2003, "Mike Wahler" <(E-Mail Removed)> wrote:
>
> > > I think overloading of functions *does* take up some extra memory when
> > > compared
> > > to using 2 functions with different names.

> >
> > IMO you think wrong. A C++ function overload *is*
> > a function with a different name. C++ simply
> > 'hides' this fact.

>
> Yes, but in doing so it takes up some extra steps which in turn results in
> comparatively slower execution and more memory.


Nonsense. Any extra steps/slower execution happens in the
*compiling* phase, not affecting the actual execution of your
particular application (I have yet to hear of a conforming C++
interpreter...), and will still happen much quicker than the
time it takes you to write out two distinct function names.

-Micah
 
Reply With Quote
 
nospam@nospam.invalid
Guest
Posts: n/a
 
      10-06-2003

On 6-Oct-2003, Micah Cowan <(E-Mail Removed)> wrote:

> "(E-Mail Removed)" <(E-Mail Removed)> writes:
>
> > On 6-Oct-2003, "Mike Wahler" <(E-Mail Removed)> wrote:
> >
> > > > I think overloading of functions *does* take up some extra memory
> > > > when
> > > > compared
> > > > to using 2 functions with different names.
> > >
> > > IMO you think wrong. A C++ function overload *is*
> > > a function with a different name. C++ simply
> > > 'hides' this fact.

> >
> > Yes, but in doing so it takes up some extra steps which in turn results
> > in
> > comparatively slower execution and more memory.

>
> Nonsense.


Be kind to me. I am just learning.

> Any extra steps/slower execution happens in the
> *compiling* phase, not affecting the actual execution of your
> particular application (I have yet to hear of a conforming C++
> interpreter...), and will still happen much quicker than the
> time it takes you to write out two distinct function names.


I've heard that a "hello" world program on C++ takes up more space when
compared with C.
Is that wrong?













 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-06-2003
(E-Mail Removed)lid <(E-Mail Removed)> scribbled the following:
> On 6-Oct-2003, Micah Cowan <(E-Mail Removed)> wrote:


(snip)

>> Any extra steps/slower execution happens in the
>> *compiling* phase, not affecting the actual execution of your
>> particular application (I have yet to hear of a conforming C++
>> interpreter...), and will still happen much quicker than the
>> time it takes you to write out two distinct function names.


> I've heard that a "hello" world program on C++ takes up more space when
> compared with C.
> Is that wrong?


Generally speaking, yes. It is also wrong that a "hello" world program
on C++ takes up *less* space when compared with C.
Neither the C standard or the C++ standard specify *anything* about how
much space the program should take. Therefore any claim that "A {C,C++}
program takes up {more,less} space than a <insert language here>
program" is invalid.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"To err is human. To really louse things up takes a computer."
- Anon
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      10-06-2003
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> On 6-Oct-2003, Ben Pfaff <(E-Mail Removed)> wrote:
>
> > Would you please cut it out with the 20-plus blank lines at the
> > end of every article?

>
> Why don't you object those who use OE and break quotes instead?


One rude or incorrect behavior does not justify another.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-07-2003
Ben Pfaff <(E-Mail Removed)> scribbled the following:
> "(E-Mail Removed)" <(E-Mail Removed)> writes:
>> On 6-Oct-2003, Ben Pfaff <(E-Mail Removed)> wrote:
>> > Would you please cut it out with the 20-plus blank lines at the
>> > end of every article?

>>
>> Why don't you object those who use OE and break quotes instead?


> One rude or incorrect behavior does not justify another.


Tell that to Clockmeister.

--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"We sorcerers don't like to eat our words, so to say."
- Sparrowhawk
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Overloading __init__ & Function overloading Iyer, Prasad C Python 4 09-30-2005 08:01 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 03:59 PM
Overloading __init__ & Function overloading Iyer, Prasad C Python 3 09-30-2005 02:17 PM
Re: Overloading __init__ & Function overloading Steve Holden Python 0 09-30-2005 01:58 PM
Re: Overloading __init__ & Function overloading Fredrik Lundh Python 0 09-30-2005 01:53 PM



Advertisments