473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

#ifdef

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 ?
Nov 14 '05 #1
5 3853


Hash 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 ?


Many places:
header files, C files, the compiler, the command line.
Nov 14 '05 #2
# #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?

There's a plethora of defines like this. They are defined by the compiler
so that a source code can adapt itself to the compiler and operating system.

# If the definition is somewhere where can i find the defnitions ?

Generally, any _<compiler-name> or _<operating-system-name> are defined or
intentionally undefined by the compilers. The compiler documentation should
explain which ones it defines and to what values.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
Nov 14 '05 #3
"Hash" <a@b.com> wrote in message news:<CC*******************@news.cpqcorp.net>...
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 can be defined any number of places: in a header file, on the
command line, in the source file, etc.

In my experience, macros which specify a platform are usually
specified on the command line, for example

gcc -D_BSD -c foo.c
Nov 14 '05 #4
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

Nov 14 '05 #5
On Fri, 17 Sep 2004 10:12:39 -0000, Benjamin Ketcham
<bk******@drizzle.com> wrote:
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 [compiles using these definitions....]

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.
Agree so far, but especially for macros beginning with underscore
there is a third possibility -- they may be "builtin" to the compiler,
which may mean actually hardcoded or simply set somewhere in the
compiler installation. For the particularly flexible and common case
of gcc, this is in a file (usually?) in a place something like
/usr/lib/gcc-lib/$arch/$version/specs . Either way they should be
described in the compiler's documentation.

<snip> 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.

This won't help for builtins however. gcc does have an option -dM to
dump out macros at the end of compilation -- which if you compile a
(perhaps dummy) program that doesn't (significantly) change the
builtins and system settings, will show you what you've got.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christopher M. Lusardi | last post by:
Hello, Is there anyway to do it other than using : #ifdef VAR1 ... #endif
5
by: lovecreatesbeauty | last post by:
Do #ifdef or #ifndef have some defects? I ever heard that some people use #if defined() or #if !defined() instead of using #ifdef or #ifndef in header file.
6
by: Michael B Allen | last post by:
Which is the preferred method for preprocessor tests and why? #ifdef XYZ or #if XYZ or #if defined(XYZ) and
8
by: kk_oop | last post by:
Hi. In our domain, we have to vary a lot of code based on a radar type (of which there are 3--for now). The legacy code acheives this by heavy use of #ifdef macros sprinkled throughout the code. ...
1
by: Michael Sgier | last post by:
Hi I get the error: No case-independent string comparison (stricmp, strcasecmp) with the code below. Why...where should stricmp be defined? And how do i get rid of the error on Linux? // //...
5
by: anushhprabu | last post by:
#include <stdio.h> #include <ctype.h> #define DEBUG 1 main() { char inbuf; int i = 0; int lcnt = 0; gets(inbuf); while(*(inbuf+i))
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
10
by: David W | last post by:
Hello, In a C++ MFC application I need to conditionally #include one of two additional resource files in my main resource file because different forms of the application have different names. I...
3
by: Andrew Gabriel | last post by:
I want to pick up the OS release during compilation in order to make up for something which is missing from a header file in a certain release. The Sun C compiler provides a built in predefinition...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.