How the compiler in C language differentiates the function and system call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suresh gani
    New Member
    • Jul 2007
    • 6

    How the compiler in C language differentiates the function and system call

    Hi,
    This is suresh, newly joined for this community . I have one doubt.


    How the gcc compiler ( C Language) on Linux platform knows which is Function call and which is the System call while compilation process ?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Hi,

    and welcome to TSDN; you're question can be much better answered in the C/C++
    Forum; please ask again overthere.

    kind regards,

    Jos

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by suresh gani
      How the gcc compiler ( C Language) on Linux platform knows which is Function call and which is the System call while compilation process ?
      It doesn't.

      During the compile, a function must be defined before it is called. If the function is not in the file being compiled, the function prototype must appear before the function is called.

      Any function (yours or a system call) that has no code but only a function prototype will be marked by the compiler as an unresolved external reference in the object file.

      The job of the linker when the object files are copied to the executable file is to locate those unresolved extrernal references. In the case of system call, the code for these functions is in libraries available to the linker. When a system function is required, the linker will copy the code for that function from the library to the executable and fix up the addresses so it looks like the system code was part of your program all along.

      Comment

      • svlsr2000
        Recognized Expert New Member
        • Feb 2007
        • 181

        #4
        Originally posted by weaknessforcats

        In the case of system call, the code for these functions is in libraries available to the linker.
        In case if add a new system call, the chances of libraries available to linker having code for this function is nill. Then how are these system calls executed.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by svlsr2000
          In case if add a new system call, the chances of libraries available to linker having code for this function is nill. Then how are these system calls executed.
          System libraries are not part of C or C++. They are part of the operating system. Or at least they are part of an SDK released with the operating system.

          So, suppose you use Windows Vista and there are 5,000 new system calls. If you use these with the Platform SDK from Windows XP you will get missing functions. You would need to install the Platform SDK for Vista to get the new libraries and then you would need to rebuild.

          Comment

          Working...