Re: Hi, What is the meaning of #ifndef



"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


.



Relevant Pages

  • Re: Origin of hoomu
    ... > The GG5 seems to say there is a difference in meaning between the ... > platforms. ... > And Googits? ...
    (sci.lang.japan)
  • Re: graphical user interface
    ... platforms are windows? ... allows an all-Fortran solution. ... Meaning $$ expensive? ...
    (comp.lang.fortran)
  • Re: Axmister Opening Special
    ... by trains from the logically wrong side meaning that passengers now ... but others such as Taynuilt and Spean Bridge have separate ... platforms but right-hand running. ...
    (uk.railway)
  • Re: is there better 32 clock() timing?
    ... The meaning of time.clockis entirely different on other platforms. ... See the documentation. ... "from time import clock" and then just clock. ...
    (comp.lang.python)
  • Re: DeviceIoControl needs header Winioctl.h
    ... On other platforms (WinCE) ... the 2-bit "method" field is the only one that has any meaning ... Providenza & Boekelheide, Inc. ...
    (microsoft.public.win32.programmer.kernel)