Home Help Center

Circular #include possible?

mefostermefoster Member Mary Ellen FosterOrganization: Heriot-Watt University, EdinburghProject: ECHOES learning environment ✭✭✭
So, say I want to accomplish something like the following, with two .ice input files, each of which needs to use types defined in the other.

file1.ice:
#ifndef _FILE1_ICE
#define _FILE1_ICE

#include "file2.ice"

module file1 {
    struct File1Struct {
        int whatever;
    };
    interface Test {
        void doSomething( ::file2::File2Struct test );
    };
};

#endif _FILE1_ICE

file2.ice
#ifndef _FILE2_ICE
#define _FILE2_ICE

#include "file1.ice"

module file2 {
    struct File2Struct {
        int whatever;
    };
    interface Test {
        void doSomethingElse( ::file1::File1Struct test );
    };
};

#endif _FILE2_ICE

When I try to run slice2java (or slice2anythingelse) on these files, I get the following errors:
file1.ice:11: `file2::File2Struct' is not defined
file2.ice:11: `file1::File1Struct' is not defined

Is there any way to accomplish this, or do I need to choose some other configuration of .ice files to get what I want?

Thanks,

MEF

Comments

  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    Hi,

    You most likely will need to choose some other configuration of slice files, such as adding a third slice file that includes those types needed by other slice file.

    common.ice:
    #ifndef _COMMON_ICE
    #define _COMMON_ICE
    
    module file1 {
        struct File1Struct {
            int whatever;
        };
    };
    
    module file2 {
        struct File2Struct {
            int whatever;
        };
    };
    
    #endif // _COMMON_ICE
    

    file1.ice:
    #ifndef _FILE1_ICE
    #define _FILE1_ICE
    
    #include "common.ice"
    
    module file1 {
        interface Test {
            void doSomething( ::file2::File2Struct test );
        };
    };
    
    #endif _FILE1_ICE
    

    In some cases you would be able to use forward declaration to avoid having to do this, but in your example the types are structs, which cannot be forward declared.

    Regards,
    Dwayne
Sign In or Register to comment.