Help in understanding small code for FreeBSD implementation of the C library

Discussion in 'C' started by tukki, Aug 14, 2010.

  1. tukki

    tukki New Member

    Joined:
    Aug 14, 2010
    Messages:
    10
    Likes Received:
    1
    Trophy Points:
    0
    Hello guys, here is the code in reference:
    Code:
    /* sys/cdef.h */ 
    #if     defined(__STDC__) || defined(__cplusplus) 
    #define __P(protos)   protos 
    #else 
    #define __P(protos)   () 
    #endif 
    /* stdio.h */ 
    #include <sys/cdefs.h> 
    div_t div __P((int, int));
    i cannot understand some parts in the code like
    1.> why is there space between div and __P in
    Code:
    div_t div __P((int, int));
    and why are there double braces around
    Code:
    __P((int,int))
    .
    2.> what is #define doing, i know these are preprocessor directives and i have seen the common implementations but i don't understand this.

    Thanks
     
  2. tukki

    tukki New Member

    Joined:
    Aug 14, 2010
    Messages:
    10
    Likes Received:
    1
    Trophy Points:
    0
    Thanks Guys but i got it. See what the code
    Code:
    div_t div __P((int, int));
    does is replace __P((int,int)) simply with () or (int,int), so that the code now becomes
    Code:
    div_t div ()
    or
    Code:
    div_t div (int,int)
    .
    A good way for making variable argument functions.

    Good day
     
  3. tukki

    tukki New Member

    Joined:
    Aug 14, 2010
    Messages:
    10
    Likes Received:
    1
    Trophy Points:
    0
    @Everyone: I would like to point out that when i said "I got it" in the above reply, i didn't mean that i solved it myself but what i meant was that i understood it, from a reply on another forum and so i have posted it here so that others who read it can benefit from the reply.

    Thanls
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice