Thread: Dynamic array in Stack ?

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    Question Dynamic array in Stack ?

    Is this a correct ?
    This is compiled with g++ (3.4) sucessfully.

    Code:
    int main()
    {
        int x = 12;
        char pz[x]; 
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by janaka
    Is this a correct ?
    This is compiled with g++ (3.4) sucessfully.
    If your aim is to write standard C++, then no, that is not correct. If your aim is to use g++'s variable length array compiler extension for g++, then yes, that is correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    And if your intention was to write C99 code then it is valid. Otherwise use std::vector<char>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic stack?
    By vikernes in forum C++ Programming
    Replies: 6
    Last Post: 06-19-2007, 01:31 PM
  2. Finished Stack
    By the pooper in forum C Programming
    Replies: 11
    Last Post: 02-02-2005, 10:52 AM
  3. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM
  4. Array Stack Problem
    By Drew in forum C++ Programming
    Replies: 3
    Last Post: 09-04-2001, 06:58 PM