Questions about a mass amount of headers

This is a discussion on Questions about a mass amount of headers within the C Programming forums, part of the General Programming Boards category; Hi i had a theory question i guess? if its called that I wanted to know what do u do ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    Questions about a mass amount of headers

    Hi i had a theory question i guess? if its called that I wanted to know what do u do when theres a bunch of class files and eventually u accidentally rewrite a header file for one class thats already redefine in another class. basically how do u avoid recalling the same header files over again with a mass of files. Im not sure if what im looking for is

    #ifndef BAR_H
    #define BAR_H

    And this is too avoid the errors and warnings about already defined functions and variables

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's how I do it...

    Code:
    #ifndef HEADER_H
    #define HEADER_H
    
    ... huge mass of stuff...
    
    
    #endif // HEADER_H
    Also many compilers support #pragma once instead, but I'm not sure if that's part of the standards or not.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Yea i actually wanted to know what #pragma once does cuz i tried googling it up and didnt find anything that could explain it to me i thought that was a good method but i used it on an itnerview and they didnt like it or thought it was completely different to use for this situation

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I use Pelles C and beginning with ver 5.0 (now at 6.0) it supports the "#pragma once" as a means of ensuring you don't double-read headers. It is pre-included in the windows headers but you need to put it in your own headers manually.

    I don't see it in my copy of the C-99 standard so if your interviewer knew the standard well, he might not be pleased to see you using non standard code.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Quote Originally Posted by CommonTater View Post
    Also many compilers support #pragma once instead, but I'm not sure if that's part of the standards or not.
    It's not standard. All #pragma are compiler-specific.
    I'm not sure to what the original question is. Include guards are used to guard against a header being included multiple times in one translation unit (read: source file). This protects against multiple definitions errors.

    Also, simply HEADER_H might not be unique enough. I recommend putting time and date into it to make it unique. Eg:

    #ifndef MY_HEADER_H_20101007_0930
    ...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    It's not standard. All #pragma are compiler-specific.
    I'm not sure to what the original question is. Include guards are used to guard against a header being included multiple times in one translation unit (read: source file). This protects against multiple definitions errors.

    Also, simply HEADER_H might not be unique enough. I recommend putting time and date into it to make it unique. Eg:

    #ifndef MY_HEADER_H_20101007_0930
    ...
    HEADER_H was only an example, used to clarify the concept.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,535
    Doesn't hurt to be specific, though. HEADER_H implies to me to be FILENAME_OF_HEADER_H, which may or may not be unique enough.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-23-2010, 03:05 PM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  4. Float/double compiler error and TONS of questions!
    By musayume in forum C Programming
    Replies: 5
    Last Post: 10-24-2001, 01:40 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21