Re: How to redefine arithmetic operators.
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 29 Nov 2005 21:05:34 GMT
jacob navia <jacob@xxxxxxxxxxxxxxxx> writes:
> Keith Thompson a écrit :
>> You don't really *need* operator overloading; anything you can do
>> with
>> it, you can do without it (with ordinary function calls).
>
> This is of course true.
>
> It is just a matter of measure.
>
> Consider this:
> qfloat a;
> qfloat q = (sqrt(a+1)/sqrt(a-1))*(cos(a+1)/cos(a-1));
>
> compared with:
>
> tmp1 = qadd(a,1);
> tmp2 = sqrtq(tmp1);
> tmp3 = qsub(a,1);
> tmp4 = sqrt(tmp3);
> tmp5 = qdiv(tmp1,tmp3);
> tmp6 = cosq(tmp1);
> tmp7 = cosq(tmp3);
> tmp8 = qdiv(tmp6,tmp7);
> result = qmul(tmp8,tmp5);
>
> This does the *same* stuff but which expression would
> you prefer???
I prefer the one that's valid C, and that I can use on systems other
than Win32.
In the context of this newsgroup (now listen carefully), *C does not
support operator overloading*. Conversely, a language that does
support operator overloading is not C. I've used languages that do
support operator overloading, and I've found it useful when used
carefully -- but those languages have their own newsgroups, as does
the lcc compiler.
And jacob, please don't send me e-mail copies of Usenet followups.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- How to redefine arithmetic operators.
- From: Raghu
- Re: How to redefine arithmetic operators.
- From: jacob navia
- Re: How to redefine arithmetic operators.
- From: Keith Thompson
- Re: How to redefine arithmetic operators.
- From: jacob navia
- How to redefine arithmetic operators.
- Prev by Date: Re: More questions on realloc - Thanks
- Next by Date: Re: C function for returning number of digits?
- Previous by thread: Re: How to redefine arithmetic operators.
- Next by thread: Re: How to redefine arithmetic operators.
- Index(es):
Relevant Pages
|