Reputation:
Where are the operators such as +
or -
defined?
E.G. Where can I see the code that says +
means add two items together?
Was reading through this but I must not be seeing the basic 1 + 1 = 2
case in the standard library section. An example of this is shown in the "Additive Operators" section, yet I cant find a location of the function definition.
Upvotes: 0
Views: 139
Reputation: 241671
In C++, there is no operator+(int,int)
. The addition operator is built-in and no function corresponds to it. In particular, you cannot do this:
using intDyadic = int(*)(int, int);
intDyadic add = operator+(int,int);
By contrast, you could create a function pointer to an operator override defined in a library, including the standard library.
Upvotes: 0
Reputation: 1
yet I cant find a location of the function definition.
There might not be a function definition at all, but a simple assembly instruction set:
mov 1,r1
mov 5,r2
add r1,r2
Upvotes: 0
Reputation:
The compiler generates the code for these operations - they are not part of the Standard Library. Your compiler will almost certainly have an option to allow you to examine the generated assembly language code.
Upvotes: 2
Reputation: 11
This is part of the language itself... the compiler translate the string "c=a+b;" to add the value stored in a to the value stored in b and set the result to c.
Upvotes: 0