Alternative to a global VLA

Member
Posts: 185
Joined: 2005.02
Post: #1
I have been working on my primitive game, and up till now I have been loading verteces and triangles form OBJ files into linked lists. I went to change the program to use VLAs instead, but ran into trouble. I need the VLAs to be global, as it is a glut program, but the C standard does not allow VLAs to have file scope. Is there a loophole or something I can exploit to allow me to use VLAs or is there some alternative? Will I just have to hard wire the array sizes in? What do you guys use for storing OBJ data?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
What exactly is a VLA?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
I have no idea what a VLA is, but I use malloc'd memory to store OBJ data... I can't imagine anyone else does anything else.
Quote this message in a reply
Member
Posts: 185
Joined: 2005.02
Post: #4
a VLA is a Variable Length Array. For example:
Code:
int n = 5;
int example[n];

So malloc is the way to go? ok thanks.
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #5
Are you sure? http://en.wikipedia.org/wiki/VLA

I fail to see the difference between your VLA which google hasn't appeared to have heard of to an array - does it say this in a textbook somewhere?
Quote this message in a reply
Member
Posts: 185
Joined: 2005.02
Post: #6
google "variable length array". Its an array whose initialization size parameter is a variable. for example:
normal array:
Code:
int normal[5];
variable length array:
Code:
int variableLength[n];
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
We know what a variable-length array is, but VLA is not a common abbreviation for it.

Incidentally, variable-length arrays are not legal in C++, ObjC, or C (prior to C99). GCC allows them by default anyway, though -- how nice of it :|
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  An alternative to Do While loops? wyrmmage 7 6,251 Dec 18, 2008 10:54 AM
Last Post: one_each
  Global Objects Simie 3 2,774 Dec 8, 2008 08:36 AM
Last Post: Simie
  PasteAll.org: A prettier alternative to RAFB Leisure Suit Lurie 2 2,916 Apr 10, 2008 04:09 PM
Last Post: Duane