38

Visual Studio syntax highlighting colors this word blue as if it were a keyword or reserved word. I tried searching online for it but the word "array" throws the search off, I get mostly pages explaining what an array is. What is it used for?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
CS student
  • 451
  • 1
  • 6
  • 11

7 Answers7

67

It's not a reserved word under ISO standards. Microsoft's C++/CLI defines array in the cli namespace, and Visual Studio's syntax highlighting will treat it as a reserved word. This usage would be considered a vendor extension and not a part of any international C or C++ standard.

ISO C99 Keywords:

auto        enum        restrict    unsigned
break       extern      return      void
case        float       short       volatile
char        for         signed      while
const       goto        sizeof      _Bool
continue    if          static      _Complex
default     inline      struct      _Imaginary
do          int         switch
double      long        typedef
else        register    union

ISO C++98 Keywords:

and         double          not                 this 
and_eq      dynamic_cast    not_eq              throw 
asm         else            operator            true 
auto        enum            or                  try 
bitand      explicit        or_eq               typedef 
bitor       export          private             typeid 
bool        extern          protected           typename 
break       false           public              union 
case        float           register            unsigned 
catch       for             reinterpret_cast    using 
char        friend          return              virtual 
class       goto            short               void 
compl       if              signed              volatile 
const       inline          sizeof              wchar_t 
const_cast  int             static              while 
continue    long            static_cast         xor 
default     mutable         struct              xor_eq
delete      namespace       switch     
do          new             template
Judge Maygarden
  • 26,961
  • 9
  • 82
  • 99
10

It isn't. At least not in standard C/C++.

Now you might well ask the reason "entry" was a reserved word in C in K&R but not in C99 - somebody thought they might add the feature at some point, but eventually decided against it.

Community
  • 1
  • 1
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
10

It's used in C++/CLI.

Visual C++ Language Reference: "The array keyword lets you create a dynamic array that is allocated on the common language runtime heap."

jeffm
  • 3,120
  • 1
  • 34
  • 57
3

Visual Studio never bothered with defining different C++ grammars for their pretty printer. ISO C++, VC++, C++/CLI, or just old C - all share the same grammar. So, names like array and interface are all treated as if they were keywords.

It would also be quite hard for the pretty printer to spot the C++ dialect used in foo.cpp. You'd need to compile the code for that. Currently the pretty printer can operate on tokens, which means it only needs to parse the code.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • 2
    On the other hand, it already has more information than just simple parsing, i.e Intellisense. I guess MS never thought it was worth the effort. – Skurmedel Jul 15 '09 at 23:29
1

In what edition? A Google search for "c++ reserved words" shows no such usage.

I routinely use "array" in sample code.

http://cs.smu.ca/~porter/csc/ref/cpp_keywords.html

warren
  • 32,620
  • 21
  • 85
  • 124
0

It is not a reserved word, but Microsoft Visual Studio decided to mark it blue as if it were a reserved word, but it most definitely is not according to "C++ Programming 5th Edition" by D.D. Malik.

phuclv
  • 37,963
  • 15
  • 156
  • 475
sdaf
  • 1
0

The fact that a word's being highlighted in MSVC doesn't mean that it's a C or C++ keyword. As you can see, it also highlights many non-standard things like __int64, or even __int128 although there's no 128-bit int type in MSVC.

phuclv
  • 37,963
  • 15
  • 156
  • 475