Previous Table of Contents Next


3.11.6 Deprecated Anonymous Types


   IDL currently permits the use of anonymous types in a number of places. For example:

   struct Foo { long value; sequence<Foo> chain; // Legal (but deprecated)

   }

   Anonymous types cause a number of problems for language mappings and are therefore deprecated by this specification. Anonymous types will be removed in a future version, so new IDL should avoid use of anonymous types and use a typedef to name such types instead. Compilers need not issue a warning if a deprecated construct is encountered.

   The following (non-exhaustive) examples illustrate deprecated uses of anonymous types.

   Anonymous bounded string and bounded wide string types are deprecated. This rule affects constant definitions, attribute declarations, return value and parameter type declarations, sequence and array element declarations, and structure, union, exception, and valuetype member declarations. For example

   const string<5> GREETING = “Hello?; // Deprecated

   interface Foo { readonly attribute wstring<5> name; // Deprecated wstring<5> op(in wstring<5> param); // Deprecated

   };typedef sequence<wstring<5> > WS5Seq; // Deprecatedtypedef wstring<5> NameVector [10]; // Deprecatedstruct A {

   wstring<5> mem; // Deprecated }; // Anonymous member type in unions, exceptions, // and valuetypes are deprecated as well.

   This is better written as:

   typedef string<5> GreetingType; const GreetingType GREETING = “Hello?;

   typedef wstring<5> ShortWName;

   interface Foo { readonly attribute ShortWName name; ShortWName op(in ShortWName param);

   };typedef sequence<ShortWName> NameSeq;typedef ShortWName NameVector[10];struct A {

   GreetingType mem; };

   Anonymous fixed-point types are deprecated. This rule affects attribute declarations, return value and parameter type declarations, sequence and array element declarations, and structure, union, exception, and valuetype member declarations.

   struct Foo { fixed<10,5> member; // Deprecated };

   This is better written as:

   typedef fixed<10,5> MyType; struct Foo { MyType member; };

   Anonymous member types in structures, unions, exceptions, and valuetypes are deprecated:

   union U switch(long) { case 1: long array_mem[10]; // Deprecated case 2: sequence<long> seq_mem; // Deprecated case 3: string<5> bstring_mem; };

   This is better written as:

   typedef long LongArray[10]; typedef sequence<long> LongSeq; typedef string<5> ShortName; union U switch (long) {

   case 1: LongArray array_mem; case 2: LongSeq seq_mem; case 3: ShortName bstring_mem; };

   Anonymous array and sequence elements are deprecated:

   typedef sequence<sequence<long> > NumberTree; // Deprecated typedef fixed<10,2> FixedArray[10];

   This is better written as:

   typedef sequence<long> ListOfNumbers; typedef sequence<ListOfNumbers> NumberTree; typedef fixed<10,2> Fixed_10_2; typedef Fixed_10_2 FixedArray[10];

   The preceding examples are not exhaustive. They simply illustrate the rule that, for a type to be used in the definition of another type, constant, attribute, return value, parameter, or member, that type must have a name. Note that the following example is not deprecated (even though stylistically poor):

   struct Foo {

   struct Bar { long l_mem; double d_mem;

   } bar_mem_1; // OK, not anonymous

   Bar bar_mem_2; // OK, not anonymous }; typedef sequence<Foo::Bar> FooBarSeq; // Scoped names are OK