help-gplusplus
[Top][All Lists]
Advanced

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

Mysterious support for dynamic arrays?


From: ondrugs
Subject: Mysterious support for dynamic arrays?
Date: 26 Oct 2006 14:35:58 -0700
User-agent: G2/1.0

On a whim I tested something the other day, which appears to work with
g++ 3.3.4.  Unfortunately it sometimes appears to exhibit flaky
behavior when statically linking... (i.e. mysterious segfault on the
line following the declaration of the array).

class Foo
{
public:
    int x;
    int y;
    int z;
};

void test(int i)
{
    Foo foo[i];

    cout << "sizeof(foo): " << sizeof(foo) << endl;
}

int main()
{
    int i;

    cout << "Val? ";
    cin >> i;

    test(i);

    return 0;
}

In the above program the function "test" will dynamically create an
array "foo" with "i" elements, which gets freed automatically upon exit
of the function.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]