Alternative to a global VLA
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?
What exactly is a VLA?
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.
a VLA is a Variable Length Array. For example:
So malloc is the way to go? ok thanks.
Code:
int n = 5;
int example[n];So malloc is the way to go? ok thanks.
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?
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?
google "variable length array". Its an array whose initialization size parameter is a variable. for example:
normal array:
variable length array:
normal array:
Code:
int normal[5];Code:
int variableLength[n];
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 :|
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 :|
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| An alternative to Do While loops? | wyrmmage | 7 | 5,084 |
Dec 18, 2008 10:54 AM Last Post: one_each |
|
| Global Objects | Simie | 3 | 2,466 |
Dec 8, 2008 08:36 AM Last Post: Simie |
|
| PasteAll.org: A prettier alternative to RAFB | Leisure Suit Lurie | 2 | 2,632 |
Apr 10, 2008 04:09 PM Last Post: Duane |
|

