Overloading methods in C API

Martin v. Löwis martin at v.loewis.de
Sun Jan 19 12:46:10 EST 2003


"James Kew" <james.kew at btinternet.com> writes:

> > The "+" operator can mean several things:
> >
> >  integer addition
> >  pointer addition
> >  floating point addition
> 
> Add, add, add. All addition. The details may vary slightly (pointer
> arithmetic, for example) but the basic semantics are the same.

So then no language has operator overloading: "+" means always "to
add".  How precisely addition acts on the internal representation
certainly varies, but this is apparently a detail that you consider
irrelevant.

I can assure you that the C compiler takes very different actions and
emits very different code depending on the types of the arguments -
just like for the user-extensible overloading in C++.

> >  unary postive
> 
> That's a different operator -- it's unary, not binary. 

Typically, people consider the number of arguments as a minor detail
when they talk about method overloading: f.foo(3) and
f.foo("Hello","world") are considered overloaded methods in C++ and
Java even though the number of arguments varies. For the same reason,
unary and binary + should be considered overloaded operators.

> The fact that it's represented by the same character in source code
> is a matter of syntax, not of operator overloading.

It appears that this is a matter of terminology. My definition is "an
operator is overloaded if the same operator has different effects
depending on the number and types of its arguments". It appears that
this terminology is shared by a number of people in this group.

My guess is that people who had formal training in a single language
will associate any term with the definition that this term had for
this language. People who have been exposed to more languages tend to
accept generalizations as useful, too.

Regards,
Martin





More information about the Python-list mailing list