I was thinking about system calls and code that we write! Lets say I have a program like below
#include<stdio.h>
int main()
{
int a=0,b=2,c;
c=a+b;
printf("The value of c is %d", c);
return 0;
}
Lets take the case of c = a+b; if it was c++ compiler, then i beleive there would be a call to operator+() function. The compiler ofcourse might optimize it by replacing it with the actual code that performs addition rather than a function call within an assembly code.
And printf will have to use system call in order to write it to different hardware buffers. So i beleive most of the api’s provided by the language would use system call to accomplish the function.. I am not sure if my understanding is correct. Please do correct me if I am wrong.
No, not at all. I’m unsure if you have your definition of a system call correct. Stealing a definition from Wikipedia:
This means that the kinds of operations that result in system calls are I/O, timing, etc — not math, assignments, (most) memory assignments, …
Even
malloc()is usually implemented so you don’t always need a system call. In general: only actions that affect or interact with the program’s surrounding enviroment require a system call. Registers, program variables, etc. do not count as part of the surrounding environment.