Mark McIntyre said:
On 25 Nov 2004 11:04:55 GMT, in comp.lang.c , "S.Tobias"
Pardon? In all cases + adds two numbers together.
No, the C `+' operators do not add two numbers, are not the same as
Mathematics `+' operation for Real numbers. Most visibly they differ
in their domain. For other example, C `+' for unsigned implements
clock arithmetic - equivalent of addition in Rings. For floats again
C `+' does not add numbers: 1e99 + 1e-99 == 1e99.
C `+' operator is of course meant to "reasonably" add things, but
these operations have their own rules and can't be thought of
as just "addition". IMHO.
There's nothing 'entirely
different' about that.
(unsigned)-1 + 1
(unsigned long)(unsigned)-1 + 1
obviously differ in value.
They will differ in machine instructions; the difference is even
more obvious for integer and float types.
The compiler decides which instructions to emit depending on
what the arguments are. What do you call it, if not "overloading"?
This compares to C++ where operator+ could be defined to mean absolutely
anything, at the users' discretion.
Not exactly: a user cannot redefine operator+ for built-in types.
But apart of that:
const Int operator+(const Int& , const Int&);
const Double operator+(const Double&, const Double&);
(for some classes Int and Double) are to each other in terms
of concept of overloading as are:
(int) + (int)
(double) + (double)
- they have different return types, and invoke different instructions.
You cannot tell what
a + b
will do until you know the types of `a' and `b'.
Qed.
And printf does different things based on its argument types. So what?
No, after the arguments have been prepared (read: thrown on the stack;
ellipsis is a language feature, there's no function or operator call
yet so we can't speak of overloading here) the sequence of instructions
issued by the compiler is the same each time. I would say that printf
is a data-driven function.