Forward referencing problem

Michele Bini mbini@dada.it
Fri, 20 Feb 1998 15:27:23 +0100


[This thread originated from a message on this list and then went on for some 
time privately. In order to sync people on the list with the past discussion I 
edited a bit Mr. Jonsson message; I hope he'll forgive me. I'm bringing the 
discussion back to the list as my opinion differs with Sai-Lai Lo one. 
Obviously I suppose he knows better than me, so I must be wrong, but I'd like 
to know why. :-) ]

On Fri, 20 Feb 1998 09:49:05 +0100  "Fredrik Jonsson" 
<fredrik.jonsson@sea.ericsson.se> wrote:

> > Define everything you use. In your example
> >
> > interface foo;
> >
> > interface foo {
> >   foo getAFoo();
> > };
>
> Does that imply that I always have to write everything in one single
> translation unit as soon as I have a circular relationship?

No. You can use the preprocessor (OMG specifies that IDL is preprocessed by an 
ANSI C compatible preprocessor). That's not a Clean Solution but it works:

interfaceA.idl:

  #if defined(INTERFACE_A)
  #define INTERFACE_A

  interface B;

  #include "interfaceB.idl"

  interface A {
    B getB();
  };

  #endif

interfaceB.idl:

  #if defined(INTERFACE_B)
  #define INTERFACE_B

  interface A;

  #include "interfaceA.idl"

  interface B {
    A getA();
  };

  #endif

> > It's just like in C++ or Java: you must define anything you use, just
> > declaring it's name is not sufficent.
> 
> In C++ forward referencing is enough as long as I only refer to the
> pointer or the reference.

I think the True Reason the IDL compiler requires to see the type definition 
is it needs it for correct marshalling [I also think last sentence is Really 
Poor English. Pardon].

-- 
                                   Michele Bini: mbini@dada.it