Thread: Infinite #define loop i can't find a way around

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    9

    Infinite #define loop i can't find a way around

    I have the files console.h, cinput.h, and typedefs.h.

    Console contains the declaration for my console class, console_t.
    Cinput (console input) contains the declaration for the object i use to accept keyboard input to enter commands. right now, only console.h needs this file.

    Console.h needs to include cinput.h so it can have its own input object.

    Typedefs.h contains some externs for global variable access. it contains an extern'd console_t, so it needs to include console.h to know what a console_t is.

    Cinput.h needs to include typedefs.h so it can access the extern'd console_t, so it can add to it with it's input function. here's my problem.

    Console includes cinput, which includes typedefs, which includes console.

    All my head files are surrounded in
    Code:
    #ifndef  FILENAME_H
    #define FILENAME_H
    
    //stuff
    
    #endif
    and i figured that would help the problem, but i still get the errors:

    (6) \source\typedefs.h: In file included from source/typedefs.h
    (7) \source\cinput.h: from source/cinput.h
    (1) \source\cinput.cpp: from source/cinput.cpp
    (21) \source\console.h: syntax error before `;'


    if i don't include typedefs.h from cinput, i compile fine, but i'm unable to see the global console from there, which i want.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Seems like the thing to do is zip and attach all the files, edited to remove clutter which doesn't affect the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    the problem is including typedefs.h from cinput.h. there are no errors or problems with my code other than that.

    Ahhhhhhhhhh i'm sorry, the subject is supposed to be Infinite #include loop. not define.
    Last edited by IonBlade; 12-18-2003 at 04:34 PM.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    How long is console.h (in lines)?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    9
    44 lines, 27 of them actual code.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    9

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Well, post a zip.

    Consider this -- never use a full definition (via #include) when a forward declaration will do instead.

    Some of this sounds like poor planning on your part at the beginning; I think you could probably have solved this problem without the need for global variables, etc., which form at least part of your problem.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Would someone solve my problem?
    By Lonners in forum C Programming
    Replies: 9
    Last Post: 01-19-2008, 06:58 PM
  2. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. edit controls in dialogs
    By Homunculus in forum Windows Programming
    Replies: 10
    Last Post: 02-23-2006, 03:38 PM
  5. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM