Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help in understanding small code for FreeBSD implementation of the C library (http://www.go4expert.com/forums/help-understanding-small-code-freebsd-t23011/)

tukki 14Aug2010 12:32

Help in understanding small code for FreeBSD implementation of the C library
 
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

tukki 16Aug2010 13:41

Re: Help in understanding small code for FreeBSD implementation of the C library
 
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

tukki 16Aug2010 20:01

Re: Help in understanding small code for FreeBSD implementation of the C library
 
@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


All times are GMT +5.5. The time now is 02:26.