By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,890 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,890 IT Pros & Developers. It's quick & easy.

Is the behaviour of * operator an example of operator oveloading in c?

P: n/a
The * operator behaves in 2 different ways. It is used as the value at
address operator as well as the multiplication operator. Does this mean
* is overloaded in c?

Jun 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
karthik wrote:
The * operator behaves in 2 different ways. It is used as the value at
address operator as well as the multiplication operator. Does this mean
* is overloaded in c?


Which one? Either way, you decide...

http://en.wikipedia.org/wiki/Operator_overloading

Note: your question is probably better suited to comp.programming.

--
Peter

Jun 20 '06 #2

P: n/a
karthik schrieb:
The * operator behaves in 2 different ways. It is used as the value at
address operator as well as the multiplication operator. Does this mean
* is overloaded in c?


No, this is not overloading, it is multiple use of the same
character as operator.
One is as a unary operator, the other as a binary operator
and there is no danger that the compiler ever confuses them
in context[*].

If you want to see it as such, then overloading takes place
for the binary operator itself and the unary operator itself:
- binary * can multiplicate pairs of ints, unsigned ints, longs,
unsigned longs, doubles, long doubles (type promotion and
arithmetical conversions take care of the rest in C90), so
if "int" is your original argument type, then the rest is
overloaded.
- unary * can get the value of the different builtin types
_and_ for user defined types like structures, i.e. whenever
you write "struct foo {....};", * is overloaded, such that
for "struct foo *pFoo;" applying * to pFoo yields a
struct foo object.

Another point of view is to say that there is no operator
overloading in standard C.

At least one C implementation provides operator overloading
as compiler extension[**].

With C99, there are "type generic math functions" which
effectively are overloaded but there is no function
overloading as such.
Cheers
Michael
[*] This danger is given for "i---j"
[**] lcc-win32
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Jun 20 '06 #3

P: n/a
Thanks 4 ur explanation Mr. Michael.
Michael Mair wrote:
karthik schrieb:
The * operator behaves in 2 different ways. It is used as the value at
address operator as well as the multiplication operator. Does this mean
* is overloaded in c?


No, this is not overloading, it is multiple use of the same
character as operator.
One is as a unary operator, the other as a binary operator
and there is no danger that the compiler ever confuses them
in context[*].

If you want to see it as such, then overloading takes place
for the binary operator itself and the unary operator itself:
- binary * can multiplicate pairs of ints, unsigned ints, longs,
unsigned longs, doubles, long doubles (type promotion and
arithmetical conversions take care of the rest in C90), so
if "int" is your original argument type, then the rest is
overloaded.
- unary * can get the value of the different builtin types
_and_ for user defined types like structures, i.e. whenever
you write "struct foo {....};", * is overloaded, such that
for "struct foo *pFoo;" applying * to pFoo yields a
struct foo object.

Another point of view is to say that there is no operator
overloading in standard C.

At least one C implementation provides operator overloading
as compiler extension[**].

With C99, there are "type generic math functions" which
effectively are overloaded but there is no function
overloading as such.
Cheers
Michael

[*] This danger is given for "i---j"
[**] lcc-win32
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


Jun 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.