Thread: How are native system calls made in standard C functions ?

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    How are native system calls made in standard C functions ?

    In the source code of C library functions, are native system calls to the OS directly made (eg. in the fopen() function, the read system call) or is it that the C program calls the corresponding win32 API functions (in Windows) and POSIX functions (in Linux) ?

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    I can't answer for Win32, but for POSIX systems, there's generally no difference between a system call and the corresponding C function provided (as in the open system call vs POSIX open()). The POSIX functions are just wrappers around a system call. As such, a C library's fopen() will just call its own open() wrapper instead of directly making a system call, but in the end there's no real difference.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    In windows the library functions do have to make system calls, just like in Linux...

    Sometimes they have to do a lot of work to make that call for you....

    Compare fopen() to the windows OpenFile()... you'll get the idea.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by daudiam View Post
    In the source code of C library functions, are native system calls to the OS directly made (eg. in the fopen() function, the read system call) or is it that the C program calls the corresponding win32 API functions (in Windows) and POSIX functions (in Linux) ?
    On Windows systems, the C library functions are usually accessed from a DLL. Internally, that code converts calls to the native format (eg: setting up an LPSECURITY_ATTRIBUTES structure, invoking CreateFile, etc), returning the results in a format that complies with C conventions. Static linking is also used at times, although much more rarely so simply because it isn't very flexible/extensible (making security updates and such problematic, as well). However, in that case the application is linked directly with the LIB file; ie: the above code would be present within the application itself. Also, a C library call would most likely translate to a "CALL to a hard-coded address", which is somewhat more efficient than the "JMPXX to index into jump table" (symbols which are fixed-up by the *loader* (ie: not at link time), that is) technique used in "dynamic" linking.
    Last edited by Sebastiani; 01-23-2011 at 05:56 PM. Reason: gramer, clarific,   rmv
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clipboard system calls
    By lsenise in forum C Programming
    Replies: 0
    Last Post: 01-17-2011, 03:15 PM
  2. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  3. list of standard c functions
    By ElemenT.usha in forum C Programming
    Replies: 7
    Last Post: 01-01-2008, 11:19 AM
  4. Ncurses and Standard Functions
    By gsoft in forum C Programming
    Replies: 2
    Last Post: 02-07-2005, 08:18 PM
  5. Links to learn standard C library functions...
    By Nutshell in forum C Programming
    Replies: 8
    Last Post: 02-01-2002, 12:41 AM

Tags for this Thread