On 9/26/14 1:36 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schue...@gmx.net>" wrote:

Alternatively, you could create a union with a private and a public
member with the same types, but I wouldn't recommend it. Besides, the
members would need to have different names:

     class Foo {
         union {
             private int a;
             public int b;
         }
     }

Hm.. that doesn't provide readonly access to either a or b.

But it gave me an idea:

class Foo {
   union {
      private int _a;
      public const int a;
   }
   void setA(int x) { _a = x; }
}

Hot damn! It works too :) Can't access _a from outside the module, can access a, but can't write it (even from within Foo). It's like an auto-inlined property function.

I don't know how it would affect the optimizer, or the GC scanner. Unions are ugly things...

-Steve

Reply via email to