including .h file in .c file of the same name?

This is a discussion on including .h file in .c file of the same name? within the C Programming forums, part of the General Programming Boards category; There is a #define that I need in both of my source files. How do I do this without getting ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    including .h file in .c file of the same name?

    There is a #define that I need in both of my source files. How do I do this without getting a duplicate error?

    Do I include the .h file into the .c file of the same name?

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Just define it in the .h and include the header in the source file.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Also:
    Code:
    #ifndef BOBO
        #define BOBO "barfoo"
    #endif
    You can include that as many times as you want.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It shouldn't matter. Your header shouldn't have anything in it that makes it not be able to be included in different .c files in the same project. I mean, you can include stdio.h in each of your .c files without it complaining ... why should yours behave any differently?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  2. Replies: 4
    Last Post: 12-14-2005, 01:21 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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