473,770 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2300
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.programmin g.

--
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
5613
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 : bigmuls = lambda xs,ys: filter(lambda (x,y):x*y > 25, combine(xs,ys)) combine = lambda xs,ys: map(None, xs*len(ys), dupelms(ys,len(xs))) dupelms = lambda lst,n: reduce(lambda s,t:s+t, map(lambda l,n=n: *n, lst))
36
3455
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 print 2.
4
2085
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 or not. My first idea, using the const and non-const versions of operator, was clearly not correct, as was pointed out. Julián Albo suggested I could use proxies to do that. I've done some googling for proxies (also in this group) and personally,...
13
2136
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 defined = 2;
7
1971
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 after the next sequence point, the >behavior is undefined. What does this actually mean? Can anyone give me a code example that leads to undefined behaviour?
2
2506
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
1393
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 base.ToString(); } }
1
2703
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 overloaded operator<<, which takes a string as input parameter and returns a reference to an ostream object (std::cout in this case). In the main file I instantiate an object of MyOut and then write a message to console in two different ways: 1....
1
1587
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 value of j repeatedlyi.e 7 where j<=7 for example.I think the problem might be with my insert function,however i see no problems.Can you help? #include <iostream> #include <iostream> #include <string> #include <stdio.h> #include...
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.