ROUGH DRAFT

C++ Attribute Syntax

Given Microsoft’s talk of attributes as extending “C++ in directions not currently possible without breaking the classic structure of the language”, one might reasonably expect that the product documentation would describe with some precision what Microsoft has done to the classic language’s grammar and syntax in order to accommodate attributes.

That something significant has been done is plain enough from the error messages produced by compiling just the following few lines:

1;

[
    2
];

The two numbers are nonsensical, of course, yet the error messages speak of the first number as a constant and of the second as a string. The first is consistent with the product documentation’s description of the C++ language. The second is a simple indication that attribute blocks are treated to very different preprocessing from ordinary C++ source code. The error message is not mistaken. It truly is that numerical constants in attribute blocks are tokenised as strings.

Put aside that purists would not even stoop to debate this as “breaking the classic structure of the language”. Ask instead how anyone at Microsoft can have implemented such different preprocessing and not thought to document it, at least not in obvious places such as the product documentation’s C++ Language Reference or its C++ Attributes Reference.

Even more puzzling are the product documentation’s indirect suggestions of the different preprocessing, as where the Attribute Programming FAQ asks “can I use comments in an attribute block?” For this to have counted with anyone as a frequently-asked question, some real-world programmer doing real-world work with C++ attributes (though possibly only at Microsoft, working for Microsoft) presumably was surprised to find that comments are sometimes not recognised in attribute blocks. But if they are not—and, indeed, they sometimes are not—then it can only be because attribute blocks have their own preprocessing, this being the stage at which comments are ordinarily discarded from C++ code.

Perhaps it is all taken as understood, given references to C++ attributes as having developed from IDL attributes in the Microsoft Interface Definition Language (MIDL).