Multiple attribute specifiers

Steve Horne stephenwantshornenospam100 at aol.com
Wed Sep 6 13:01:52 PDT 2006


On Wed, 06 Sep 2006 13:53:05 -0500, Chris Nicholson-Sauls
<ibisbasenji at gmail.com> wrote:

>Comments imbeded.
>
>Ary Manzana wrote:
>> If I write this inside a module:
>> 
>> --------------------------------------
>> public private int x;
>> --------------------------------------
>> 
>> it compiles perfectly.
>
>Okay this is odd, indeed.  I would expect an error from contradictory attributes applied 
>directly to a single decleration.  I consider this a bug, personally.

I'd guess it falls out of allowing several access modifier styles...

class xxx
{
  public:
    private int x;
}

This makes sense. The C++-like colon can be seen as changing a default
that runs on until the next access modifier. The Java-like variant is
more convenient for a this-declaration-only access modifier. With the
block version supported as well, it's obviously mainly about keeping
C++ and Java programmers happy, but there is a logic to layering
access modifiers.

In the compiler, it's probably easier to handle that as 'the last
modifier is the real one' than to sort out different cases, and have
more specific rules.

Also, the grammar probably just allows modifiers to be added to
declarations arbitrarily. Should 'private' go before or after
'static'? Why not allow both cases. But the easiest way to allow both
cases will also allow two access modifiers, or two storage modifiers.

After all, the following compiles fine too...

  static static int m_Var;

No contradiction in that, of course, but still pretty wierd.

The question is... is this really a problem?

-- 
Remove 'wants' and 'nospam' from e-mail.



More information about the Digitalmars-d-learn mailing list