473,287 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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

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
3 2256
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ben | last post by:
Hi all, I'm trying to figure out how how complex map, filter and reduce work based on the following piece of code from http://www-106.ibm.com/developerworks/linux/library/l-prog.html : ...
36
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested...
4
by: Mark Stijnman | last post by:
A while ago I posted a question about how to get operator behave differently for reading and writing. I basically wanted to make a vector that can be queried about whether it is modified recently...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
7
by: Andy Lomax | last post by:
The C99 standard contains various statements like this one (in this case, 6.5.16, assignment operator): >If an attempt is made to modify >the result of an assignment operator or to access it...
2
by: vivekian | last post by:
Have a pointer to an object of class type task task * A ; Now this object takes operator overloading like A<<2 ; which assigns the number 2 to one of the members of the object A.
6
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I found a really strange quirk in the C# compiler, which I can't beleive is proper behaviour. If I define a class thus: public class MyClass { public override string ToString() { return...
1
by: buburuz | last post by:
Hi, I have a question about overloading operator<< . Actually I am trying to understand how it works when chaining multiple calls to this operator. I have a very simple class (MyOut) with an...
1
by: dynamo | last post by:
hi everyone,i dont understand the behaviour of my generate function using a nested loop that performs my insert function repeatedly.Instead of inserting the value of i,it seems to insert the maximum...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.