Question

I have the following CORBA IDL 3.2, which attempts to declare a mutually recursive structure:

module SE
{
  interface SE
  {

typedef unsigned short MenuItemID; // a small integer representing a unique menu item

enum MenuSubaction { CollectCharacter, CollectStruct };

struct MenuItemAction;   // forward declaration

union MenuSubactionParameter switch (MenuSubaction)
{  case CollectStruct:  MenuItemAction sub_structure;    // <<<<<<<<< use of forward
};

struct MenuItemAction {   MenuSubaction menu_subaction;
              MenuSubactionParameter menu_subaction_parameter;
              };
  }; // interface
}; // module

I get a complaint from Sun JDK 1.7 idlj on the line marked with <<<<<

 ... SE.idl (line xx): Illegal reference to incomplete forward declaration of type MenuItemAction.

Note: this isn't a "forward interface" declaration.

What's an "incomplete forward declaration"? (If you successfully declared as a forward declaration, I wouldn't think the forward declaration as incomplete, just not yet defined. Maybe that's just an easy to misinterpret phrase).

More importantly, how do I manage to define my recursive structure?

I'm new to CORBA, so I don't really :-} know what I'm doing. I don't see why CORBA can't define such recursive structures; one transmits a particular instance that won't be recursive. In particular, this one forms a tree, which should be "easy" for CORBA to send.

EDIT: Brian had the right answer. I needed to replace the direct mention of the forward reference,

         MenuItemAction sub_structure

with

         sequence<MenuItemAction> sub_structure>  
Was it helpful?

Solution

You can forward declare structs, but there are many restrictions.

Edit: I don't know what version of CORBA you are using, but in the 2.6.1 specification it says in section 3.10.2.3 (emphasis mine):

The IDL syntax allows the generation of recursive structures and unions via members that have a sequence type.

And later:

IDL supports recursive types via a forward declaration for structures and unions (as well as for valuetypes).

And later:

An incomplete type can only appear as the element type of a sequence definition. A sequence with incomplete element type is termed an incomplete sequence type.

An incomplete sequence type can appear only as the element type of another sequence, or as the member type of a structure or union definition.

Example:

struct Foo; // Forward declaration; Foo is incomplete
typedef sequence<Foo> FooSeq;  // incomplete sequence type
struct Foo {
   long value;
   FooSeq chain; // incomplete seq. type used as struct member; OK
};

Much more information can be found in the link, including this example, which may be closer to what you want to do:

union Bar; // Forward declaration
typedef sequence<Bar> BarSeq;

union Bar switch(long) { // Define incomplete union
   case 0:
      long l_mem;
   case 1:
   struct Foo {
      double d_mem;
      BarSeq nested; // OK, recurse on enclosing
                     // incomplete type
   } s_mem;
};

OTHER TIPS

It seems to be a known bug "4754974 : idlj does not support forward declaration of struct and unions": http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4754974

after the comments above i tried out:

module SE
{
  interface SE
  {

    typedef unsigned short MenuItemID; // a small integer representing a unique menu item

    enum MenuSubaction { CollectCharacter, CollectStruct };

    struct MenuItemAction;   // forward declaration

    union MenuSubactionParameter switch (MenuSubaction)
    {
      case CollectStruct:  sequence<MenuItemAction> sub_structure;    // <<<<<<<<< use of forward
    };

    struct MenuItemAction {
      MenuSubaction menu_subaction;
      MenuSubactionParameter menu_subaction_parameter;
  };
}; // interface

which works.You'll end up with a sequence instead of a single record but for pratical purposes that might not be an issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top