Circular Dependency error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Circular Dependency error

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Circular Dependency error

    Hi ,

    I was doing Uni assignment ( not looking for a full solution ) had to use the start up code provided ( other wise this issue would not have come ),
    when compiling the source I get the following error

    "pms_program.h:54:56: error: expected declaration specifiers or ‘...’ before ‘CourseType’"

    the code you are looking for in pms_course.h ( there is a circular dependency between pms.h , pms_course.h and pms_program.h)
    Head tutor provided a GUARD however don't think it works properly

    function prototype AppendProgram ( part of doubly linked list )



    I have attached the full course code.

    As much as I like I cannot change the structure of the startup code , I was hoping that someone know a solution or cam point me to the problem

    please see attached zip file for the entire source code.

    Thanks for Stopping by.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Circular Dependency error

    I'm not too keen to uncompress that and look through all the possible files, so I'll just say this: sketch out the dependencies. What headers are included where? Do you define a class such that it requires the definition of another class that requires its definition?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Circular Dependency error

    Quote Originally Posted by aamir121a View Post
    Hi ,

    I was doing Uni assignment ( not looking for a full solution ) had to use the start up code provided ( other wise this issue would not have come ),
    when compiling the source I get the following error

    "pms_program.h:54:56: error: expected declaration specifiers or ‘...’ before ‘CourseType’"

    the code you are looking for in pms_course.h ( there is a circular dependency between pms.h , pms_course.h and pms_program.h)
    Head tutor provided a GUARD however don't think it works properly
    How is this supposed to work (from pms.h)?
    Code:
    /* program header files */
     #include "pms_program.h"
     #include "pms_course.h"
     #ifndef PMS_H
     #define PMS_H
    This is a non-starter right there.

    Secondly, there is no way to fix the problem of circular dependency unless you change the code.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Circular Dependency error

    this is strictly a c code ( so no classes ) problem comes from the fact pms.h in included in pms_courses.h and pms_program.h and the are included in pms.h . ( hence the circular dependency )
    please also look at the typdef in pms.h
    Code:
    /* predeclare the program and course structs */
    typedef struct program* ProgramTypePtr;
    typedef struct course* CourseTypePtr;
    using them seems to solve the problem , however I do not understand why , perhaps an explanation will help me in the future.

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Circular Dependency error

    Quote Originally Posted by aamir121a
    this is strictly a c code ( so no classes )
    The same applies to structs.

    Quote Originally Posted by aamir121a
    using them seems to solve the problem , however I do not understand why
    It is probably because you are then not including the headers but using forward declarations instead.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: Circular Dependency error

    The .c file that doesn't compile is pms_course.c. To enable this to compile, the following change should be made

    Code:
    /*#include "pms_course.h"*/
    #include "pms.h"
    The other .c modules compile with only a couple of warnings.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: Circular Dependency error

    Thank you all for posting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center