Hash <a@b.com> wrote:
I have a small doubt,
#ifdef _BSD
When we use #ifdef preprocessor directive, the parameter which we pass
(in this case _BSD) is it defined by the user or is it defined somewhere
else?
If the definition is somewhere where can i find the defnitions ?
It may be defined by the user, or somewhere in a header file,
or in other project files such as "Makefile". If the documentation
is any good, it should tell you what symbols are defined, and where.
Often, especially under Unix and its ilk, compiling software
is a two step process: the first step, "configure", queries your
system and creates one or more header files containing bunches of
macro definitions representing what kind of system it is; the
second step, "make", then fires off the actual C compiler, which
makes use of the definitions to customize the compilation to your
environment. The definitions may include "big-picture" attributes
such as is the system more like BSD or more like SYSV, etc., and
much smaller details like what functions are available, what is
the CPU endianness, etc..
I would expect the symbol in question, "_BSD", to be defined
automatically for you, if it is needed, either in a header file
that is part of the software package, or in a system header file
(often located under /usr/include on Unix), or as part of the
"configure" process.
Just a guess, but you may be encountering difficulties related to
this symbol because you have taken a small snippet of code, or a
single C file, out of a larger context such as the OS source code
or the source code for a large application or library, and you
are trying to compile this snippet as a standalone program, or
you are trying to integrate it with a project of your own.
In general, this type of "cannibalism" can have subtle gotchas
as well as obvious ones like undefined symbols, so be careful.
I wouldn't say don't do it, though, because there's much to learn
through trying.
Many compilers have options to verbosely print out directories
where they are searching for header files, and to display the
C code after preprocessing but before compiling. These can help
in tracking down issues with preprocessor symbols.
--Benjamin