Results 1 to 4 of 4

Thread: pre processing directvies ???

  1. #1
    mahesh_575
    Guest

    Question pre processing directvies ???

    What is the meaning of #ifndef ??? is it like #define or if condition ?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    if not defined.
    when you define something with
    #define something
    the compiler won't process what is between
    #ifndef something
    and the next
    #endif something
    where something obviously could be replaced with anything. if you remove the #define line, the lines will be processed.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    mahesh_575
    Guest
    Kedaman

    Thank you very much ! But here I have some code like this

    #ifndef XYZ
    #define XYZ
    one structure declaration
    #endif

    Here what will happen ?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is to make sure that the structure will be declared only once:
    First time the compiler sees this:
    #ifndef _STR_DEF
    _STR_DEF is not defined, so the compiler (actually the precompiler) will execute the code:
    #define _STR_DEF
    struct str
    .
    .
    .
    #endif

    Due to nested including, the same header is included a second time, but this time, _STR_DEF is already defined, so the compiler will skip the struct definition, thus preventing an error.

    This method is commonly used to prevent headers from being included twice:

    #ifndef _MY_HEADER_INCLUDED_
    #define _MY_HEADER_INCLUDED_
    .
    .
    .
    #endif // _MY_HEADER_INCLUDED_

    in VC++, you could also use:
    #pragma once

    but that is not portable.

    All the buzzt
    CornedBee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width