35398

Is “array” a keyword under c++11 standards?

Question:

While using "array" as an identifier Codeblocks highlighted it like the other keywords. I searched it up in <a href="https://stackoverflow.com/questions/372580/why-is-array-a-reserved-word-in-c-c?answertab=votes#tab-top" rel="nofollow">Why is "array" marked as a reserved word in Visual-C++?</a>

But the answers were outdated. If yes, how is it used ?

Answer1:

No, array is not a keyword.

Still, there is a C++11 standard-library type: <a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">std::array</a>, a fixed-length array container.

Here a list of the keywords from the C++1y draft:

alignas continue friend register true alignof decltype goto reinterpret_cast try asm default if return typedef auto delete inline short typeid bool do int signed typename break double long sizeof union case dynamic_cast mutable static unsigned catch else namespace static_assert using char enum new static_cast virtual char16_t explicit noexcept struct void char32_t export nullptr switch volatile class extern operator template wchar_t const false private this while constexpr float protected thread_local const_cast for public throw

These alternative representations (whose very existence I dislike, but that's just me) are not keywords though still reserved:

and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq

Contextual keywords (override control, put at the end of the function declaration in a class (new not listed because already a keyword))

final override

Answer2:

array is not a keyword, but the C++11 standard defines its STL with a <a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">std::array template container</a>. You should prefer

std::array<int,5> tab;

instead of int tab[5]; because std::array have interesting functions and works better with other parts of the STL library.

Since it is a standard container, I would advise you to avoid using the array (or vector, because of std::vector, etc...) identifier in your own code (especially in reusable headers), to avoid future potential conflicts with <array> header, and also for readability reasons. But in principle you could define your own array but I don't recommend that.

Answer3:

array is a standard container, as you can see <a href="http://www.cplusplus.com/reference/array/" rel="nofollow">here</a>.

It doesn't belong to the keywords, but it's part of the standard library.

Answer4:

C++ Keywords are listed in the <strong>C++ standard, section § 2.13</strong>.

array is not listed there, so it isn't.

<hr />

<strong>Note:</strong>

<ul><li><a href="http://en.cppreference.com/w/cpp/container/array" rel="nofollow">std::array</a> is a standard type, but not a keyword.</li> <li>array is a valid identifier, but it certainly is discouraged because of the previous point.</li> </ul>

Recommend

  • Pass member function pointer in C++
  • Accessing derived class-only methods using base class object
  • C++ dynamic_cast vs storing object type in a static enum?
  • 'Series' objects are mutable, thus they cannot be hashed error calling to_csv
  • Automatic process monitoring/management with Python
  • Making bash script to check connectivity and change connection if necessary. Help me improve it?
  • Shell environment variables in vagrant files are only passed on first up
  • Using `diff` from R via `system(..)`
  • Check for stdout or stderr
  • F# deleting common elements in lists
  • F# NativePtr.stackalloc Unexpected Stack Overflow
  • Running exec() command with dev>null & doesn't work, but dev>null does
  • css Star-rating html
  • python - terminate child process when script invoked from bash
  • How is user.dir configured for Tomcat servlets?
  • Error building MEX-files (MATLAB 2012a) on Kubuntu '/usr/bin/ld: cannot find -lstdc++'
  • date: illegal option — d, Find difference between two dates
  • OSStatus error -50 (invalid parameters) AudioQueueNewInput recording audio on iOS
  • mCamera.setpreview{@override onPreviewFrame() } not work
  • How to work with AMMediaType for video filters
  • How to align an image side by side with a heading element?
  • Syntax error near unexpected token 'elif'
  • Building jamvm 1.5.4 on OS X Lion
  • How to unpack 32bit integer packed in a QByteArray?
  • How can I get the full list of running processes on a Mac from a python app
  • bad substitution shell- trying to use variable as name of array
  • Content-Length header not returned from Pylons response
  • Use of this Javascript
  • Play WS (2.2.1): post/put large request
  • How to access EntityManager inside Entity class in EJB3
  • Linq Objects Group By & Sum
  • Why is the size of this struct 32?
  • sending/ receiving email in Java
  • vba code to select only visible cells in specific column except heading
  • Unanticipated behavior
  • How to format a variable of double type
  • How to delete a row from a dynamic generate table using jquery?
  • Buffer size for converting unsigned long to string
  • Proper way to use connect-multiparty with express.js?
  • Checking variable from a different class in C#