Re: Hi, What is the meaning of #ifndef
- From: "Alex Fraser" <me@xxxxxxxxxxx>
- Date: Sat, 16 Apr 2005 14:08:09 +0100
"Qiao Jian" <tecsure@xxxxxxxxx> wrote in message
news:a86f9c58.0504160309.10e26339@xxxxxxxxxxxxxxxxxxxxx
> I am new to c. Today I just read an h file within which there is
statements:
>
> #ifndef _RANDOM_H
> #define _RANDOM_H
>
> So what is the meaning or purpose of this statement?
"#ifndef identifier" means "if 'identifier' is not defined as a macro".
> When should I use such statement in my own program?
It's generally a good idea whenever you create header files; the idiom above
is part of what is usually called an "include guard". See
http://www.eskimo.com/~scs/C-faq/q10.7.html
Another time when #ifndef and #ifdef are useful is when you develop code
that is to be compiled on multiple platforms. Slight differences between the
platforms can be allowed for by conditionally including code relevant to the
platform for which the source is being compiled (and excluding code for
others).
Alex
.
- References:
- Hi, What is the meaning of #ifndef
- From: Qiao Jian
- Hi, What is the meaning of #ifndef
- Prev by Date: Re: Hi, What is the meaning of #ifndef
- Next by Date: Re: multiple definition of `fVar'
- Previous by thread: Re: Hi, What is the meaning of #ifndef
- Next by thread: Re: Hi, What is the meaning of #ifndef
- Index(es):
Relevant Pages
|