Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C++ replace built-in operators with function calls?

I was recently reading about operator overloading in C++. So, I was wondering whether the built-in operators are replaced by function calls behind the scenes.

For example, Is a + b(a and b are int types) replaced by a.operator+(b)? Or the compiler does something different?

like image 471
Romok Das Avatar asked Nov 16 '25 16:11

Romok Das


1 Answers

There is no int::operator+. Whether the compiler chooses to compile a + b directly to assembly (likely) or replace it with some internal function like int __add_ints(int, int) (unlikely) is an implementation detail.

like image 100
Brian Bi Avatar answered Nov 19 '25 08:11

Brian Bi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!