CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    23

    Arrow #define question

    1.I see in some classes, there are

    #ifndef IPADD_H
    #define IPADD_H
    #endif

    What is that #xxx for ?
    2.I also see

    #define something somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse...........
    Very long, the whole screen
    WHy should they define something like that ? When should we do so ?

    Thank you

    --Sunny Smile

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: #define question

    Quote Originally Posted by SunnySmile View Post
    1.I see in some classes, there are

    #ifndef IPADD_H
    #define IPADD_H
    #endif

    What is that #xxx for ?
    These are include guards. They prevent a given header from being #included more than once during a given compile. For instance, if A.h #includes both B.h and C.h, and C.h also #includes B.h, we only want one copy of B.h in the final preprocessed file and this ensures we only get one.

    Note, include guards cannot protect against linker errors.

    #define something somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse...........
    Very long, the whole screen
    WHy should they define something like that ? When should we do so ?
    Some C programmers like to use macros to reduce the amount of repeated code they need to type. However, macros are difficult to debug, and in most cases C++ provides superior compile-time (as opposed to preprocess-time) alternatives such as templates and inline functions.

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

Featured