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

tukki's Avatar, Join Date: Aug 2010
Go4Expert Member
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
0
tukki's Avatar, Join Date: Aug 2010
Go4Expert Member
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
0
tukki's Avatar, Join Date: Aug 2010
Go4Expert Member
@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