[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Questionable g++ behaviour



I am by no means a guru in C++, so I come to the list to ask advice. I have been informed that C++ does not allow for array declarations using varaibles as the size parameter:

<data_type> <array_name>[<variable>]

Yet g++ clearly allows this. Is this my misunderstanding? If so, can anyone point me in the direction of the appropriate C++ specs so that I may use as evidence? Or is this a bug or gotcha in g++? If so, should I file a bug report?

I have attached a sample .cpp which compiles and runs for me.

Thank you.
--
As a boy I jumped through Windows, as a man I play with Penguins.
#include <iostream>
using namespace std;

int main()
{
    int array_size = 5;
    int array[array_size];

    for (int i = 0; i < array_size; i++) {
        array[i] = i*i;
    }

    for (int i = 0; i < array_size; i++) {
        cout << array[i] << endl;
    }

    return 0;
}

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]