K
Keith Thompson
Jens Schweikhardt said:in <[email protected]>:
#> If a, b, and c are of some built-in type, then `a = b + c;` cannot
#> involve any function calls in either C or C++.
#
# Sure it can. It could involve a call to a function called __addquad().
Seebs of course makes a good point. My point was that even in C++,
you can't overload an operator for a built-in type that already
has that operator. You can't write your own
double operator+(double, double);
that will be invoked when you add two double values.
And even if addition for some type is implemented as a function
call, its semantics are still defined by the standard's rules for
operators, not by the rules for function calls.
I remember Dan Pop once told me about a C implementation for a Z80 (an
8-bit CPU). On this CPU, 16bit addition uses two of three register pairs
("ADC HL,BC") and I'm confident it would call a function saving and
restoring the registers clobbered.
I would be unsurprised if the saving and restoring of the registers
were done with inline code rather than function calls. But I'm
not familiar with the Z80, and perhaps a function call saves enough
code size to make it worthwhile.