Thread: Define Header File

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    26

    Define Header File

    I have read a few ways to define a header file. What is the right way to do it?

    This is from the C Programming Preprocessor tricks:

    http://www.cprogramming.com/tutorial/cpreprocessor.html

    Code:
    #ifndef _FILE_NAME_H_
    #define _FILE_NAME_H_
    
    /* code */
    
    #endif // #ifndef _FILE_NAME_H_
    And this is from wikipedia's page on #include guard.

    http://en.wikipedia.org/wiki/Include_guard

    Code:
    #ifndef GRANDFATHER_H
    #define GRANDFATHER_H
    
    struct foo {
        int member;
    };
    
    #endif
    Are you supposed to put underscores at the start and end of the header name? Or are you supposed to just put them before the H?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Are you supposed to put underscores at the start and end of the header name?
    You're not supposed to use leading underscores, or more than one consecutive underscore (unless you are the implementation, because those identifiers are reserved for the implementation). Anything else is fair game. There's nothing special about these names, just make sure they follow the rules for a valid identifier and don't clash with other names.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    Ok, thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  2. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 10:02 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Replies: 6
    Last Post: 04-02-2002, 05:46 AM