The following code compiles fine on majority of compilers (include Microsoft Visual Studio’s – cl, Minimalist GNU for Windows – MinGW) but fails on Digital Mars Compiler – dmc with the error: Error: type qualifiers and static can only appear in outermost array of function parameter
const int MAXLENGTH32 = 32;
typedef char String32[MAXLENGTH32];
void f1(const String32 tokens[]) {
}
int main() {
return 0;
}
I would like to state the following:
-
The first reason I am posting this is to get expert opinion on why the code fails on a popular compiler (Bjarne Stroustrup himself recommends it http://www2.research.att.com/~bs/compilers.html). The main problem seems to be the use of
constwith the parameter. If you removeconst, the code compiles fine on the DMC compiler. -
The second important reason is that in my investigation on the possible explanation for compilation failure, I did not come across any conclusive explanation. Worse, I came across the suggestion: “C++ programmers to just avoid using const”. The poster went on to say that its rather difficult to figure out just what the specifications says about the usage of
constin a scenario like above and that these kinds of things are why const, as a type modifier, is not in D (- to paraphrase sort of). -
The last personal reason for this post is that most exceptional things I have learnt about C++ language have been borne out of not taking a stance like it-compiles-on-all-the-rest-so-damn-it-and-move-on. Yes. Am eager to hear expert opinion on what could make what would seem like normal code fail on DMC compiler just like that. Thanks.
The obvious explination is that there is a bug in dmc. The error
message is excedingly confusing: for starters,
staticcannot appearanywhere in a function parameter, outermost or otherwise. As for type
qualifiers, the standard is clear that type qualifiers on an array apply
to the individual elements of the array (and that this applies
recursively). Written canonically, your function declaration would be:
, which, after application of the typedef, becomes:
Which is perfectly legal.