Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:57:39+00:00 2026-06-06T16:57:39+00:00

With the code, const double rotationStep = 0.001; const int N = 2*int(M_PI/rotationStep) +

  • 0

With the code,

const double rotationStep = 0.001;
const int N = 2*int(M_PI/rotationStep) + 3;

static unsigned int counts[N];

g++ gives the error:

array bound is not an integer constant before »]« token

I am using g++/gcc version 4.6.1

Can anybody tell me why g++ complains about the expression?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:57:40+00:00Added an answer on June 6, 2026 at 4:57 pm

    As of the ISO C++ standard of 2003, that’s not an integral constant-expression. Quoting section 5.19 of the standard:

    An integral constant-expression can involve only literals (2.13),
    enumerators, const variables or static data members of integral or
    enumeration types initialized with constant expressions (8.5),
    non-type tem-plate parameters of integral or enumeration types, and
    sizeof expressions. Floating literals (2.13.3) can appear only if
    they are cast to integral or enumeration types.

    You could change this:

    const double rotationStep = 0.001;
    const int N = 2*int(M_PI/rotationStep) + 3;
    

    to this:

    const int inverseRotationStep = 1000;
    const int N = 2*int(M_PI)*inverseRotationStep + 3;
    

    (That’s assuming M_PI is defined somewhere; it’s not specified in the standard, but it’s a common extension.)

    The 2011 ISO C++ standard loosens this up a bit. 5.19p3 (quoting the N3337 draft) says:

    An integral constant expression is a literal constant expression of
    integral or unscoped enumeration type.

    I think 2*int(M_PI/rotationStep) + 3, and therefore N, qualifies under the new rules, but it’s likely your compiler doesn’t yet implement them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code gives a compiler error in C++: const double** x; const void**
I'm writing code in C++ and have defined PI as: const double MathConstants::PI =
consider the following code: const QString& MyClass::getID(int index) const { if (i < myArraySize
I'm a bit confused what happened in the following code: const int e =
I saw this code snippet const volatile int * volatile * const X; but
i have the following code below: const char* timeformat = %Y-%m-%d %H:%M:%S; const int
There is this code: #include <iostream> template<const double& f> void fun5(){ std::cout << f
There is this code: #include <iostream> template<const double& f> void fun5(){ std::cout << f
I stumbled upon .NET's definition of double.NaN in code: public const double NaN =
// main.cpp const double MAX = 3.5; namespace ns { const int MAX =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.