Thread: '_' character in .h files

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    61

    '_' character in .h files

    Hi
    I am looking codes in header files
    for example when someone declare a header file (we say its names is MY_HEADER_FILE).
    then write in:
    Code:
    #ifndef MY_HEADER_FILE_H
    #define MY_HEADER_FILE_H
    Here why dont we write MY_HEADER_FILE.H instead of MY_HEADER_FILE_H.What is the purpose of using ' _'?

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    It's just convention.... Anything will work as long as you don't have the same #define statement in two different header files.

  3. #3
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    DougDbug is right, but you can't use a . in the preprocessor (the thing that handles #define)

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    A macro name is not much different from other identifiers (class name, variable names, ...), so it is restricted to the same characters to make it up. These are alphanumeric characters and the underscore, and no number as the first character.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    61
    thanks for answers.
    I asked this because i heard that c compiler write function names to the .obj file by put '_' character in front of function names.And c++ comp. put some character about its parameters.
    Here we put '_' instead of '.' in header files when defining a header.I wonder that is this a compiler specification? Or c++ specification?What is the rule of writing such a expression.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Convention, mere convention. Since you can't use ., you have to use something else, and the only non-alphanumeric character available is _.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  4. Cant Make heads or tails of .h files
    By D3T in forum C++ Programming
    Replies: 4
    Last Post: 07-09-2002, 10:03 AM
  5. Class files (.h and .cpp
    By Todd in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2002, 03:07 PM