Thread: #endif ?

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    160

    #endif ?

    #if !defined
    #ifndef
    #endif

    what does these two do
    Last edited by Zahl; 11-12-2002 at 09:01 AM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    Code:
    #ifndef something
    #define something
    
    //..
    
    #endif
    that is what is called an inclusion guard. it forces headers to only be included once, so you arent re-defining things that have already been defined. i just recently learned how to use those myself, and they come in handy when you have a large project with multiple files.

    say you have a 'main' header file, and you have a few 'sub-' header files, and then your main cpp file. if you include your main header file in your sub-header files, and then include both your main and sub header files in your main cpp file, then you are including your main header file twice which is unnecessary. inclusion guards prevent you from accidentally doing it (or rather, allow you to accidentally do it and not cause any problems).
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    Okay but now we are on the subject what is #pragma and though I know what "#define GOD 15" do I don't know what "#define SoegH" could possible do.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    check this out ...

    answer
    I hope this helps!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    That is quite a bit to go through so if there is a simple ansver...
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    anytime you see:

    Code:
    #define (something)  (something else)
    its saying every time you see the first something, replace it with the something else. you know that, as youve stated.

    whenever you see just:

    Code:
    #define (something)
    you are just telling the compiler not to freak out whenever it sees the 'something'

    if you use a:

    Code:
    #ifndef (something)
    #define (something)
    
    //...
    
    #endif
    then you arent really accomplishing anything, code-wise. the something that you defined is never used as a macro, nor does it need to be. the actual function of that is to prevent from using that code more than once.

    the first time the program runs into that bit of code it says "have i defined this yet? no? ok then, its defined now." and it actually defines it with all of the code in between that and the #endif.

    then, when you try to include that code again later, it says "have i defined this yet? yes? ok then, im skipping down to the #endif." thus saving you from having the program say "hey wait a minute! i already defined these variables/functions. i cant do it again!"


    (by the way, if you actually hear your program talking to you, it means its time for a break)
    Last edited by ...; 11-12-2002 at 11:54 AM.
    I came up with a cool phrase to put down here, but i forgot it...

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    #pragma sets compiler specific conditions. you are going to need to look at your compiler documentation to know what arguments there are and their uses.
    I came up with a cool phrase to put down here, but i forgot it...

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    hehe... a talking compiler. Long live the future!
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Compile via makefile?
    By Blackroot in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2006, 12:00 AM
  5. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 09:58 AM