Thread: dynamic-variable-sized array

  1. #46
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    Quote Originally Posted by itCbitC
    I mean int
    Ah, but that is actually not as confusing as it looks at first. I put the code to the MinGW port of gcc 3.4.5, and since I did not enable the -std=c99 flag at the time, it gave the warning "ISO C90 forbids variable-size array `type name'". It then became clear that just as int[N] is the type of an int array of size N, int[nnode+1] is an int array of size nnode+1, even if nnode is a variable, assuming that the variable length arrays feature is available.
    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

  2. #47
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by laserlight View Post
    Ah, but that is actually not as confusing as it looks at first. I put the code to the MinGW port of gcc 3.4.5, and since I did not enable the -std=c99 flag at the time, it gave the warning "ISO C90 forbids variable-size array `type name'". It then became clear that just as int[N] is the type of an int array of size N, int[nnode+1] is an int array of size nnode+1, even if nnode is a variable, assuming that the variable length arrays feature is available.
    I never ran it through a compiler except now and what's interesting is that the C89 one works for me while the C99 one gives errors. Oh well live and learn.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Array
    By firetheGlazer in forum C Programming
    Replies: 4
    Last Post: 07-11-2008, 11:57 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Replies: 4
    Last Post: 11-02-2006, 11:41 AM
  4. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM
  5. making an array name a variable
    By Zaarin in forum C++ Programming
    Replies: 5
    Last Post: 09-02-2001, 06:17 AM