If I understand well, it also prevents the following common pattern to work
int array[..]; for( i = 0 ;i < (sizeof(array)/sizeof(array[0])); ++i) -----Original Message----- From: tinycc-devel-bounces+eligis=orange...@nongnu.org [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Joe Soroka Sent: vendredi 8 avril 2011 08:33 To: tinycc-devel@nongnu.org Subject: Re: [Tinycc-devel] Best workaround for VLA's On Thu, Apr 7, 2011 at 9:50 PM, Luis Alejandro Muzzachiodi <lamuzzachi...@yahoo.com> wrote: > > Until now i was using successfully TCC with a multiplatform library. > However in the last time the author begin to use VLA's (and tough i'm trying that not, it's very possible that he keeps and/or increases more your use). > So, what's would be the best workaround in TCC for stuff like: > char str[i+15]; > or > float flt[veclen]; > etc.? > I mean, the simplest option could be the max possible length, sure; but i haven't idea of max size of these arrays ... > Having this on mind, what's the best alternative (if exists...) ?. I'm planning to push a modified version of Thomas Preud'homme's VLA patch very soon that might solve your problem. But basically what I've been doing, is just converting those things to alloca() calls. So, char str[i+15]; float flt[veclen]; becomes char *str = alloca(sizeof(char)*(i+15)); float *flt = alloca(sizeof(float)*veclen); The problem with that approach is that it doesn't work with multidimensional arrays, doesn't work with function parameters, and most importantly doesn't work with sizeof. For example, there's no alloca equivalent for multidimensional dereferencing: char str[i+15][10]; str[0][0] = 123; Also, there's no obvious equivalent for something like the VLA example in "C in a nutshell": double maximum(int nrows, int ncols, double matrix[nrows][ncols]) { /* ... */ } Finally, float flt[veclen]; memset(flt, 0, sizeof(flt)); doesn't work. You can of course just use memset(flt, 0, sizeof(float)*veclen); instead, but "veclen" may have changed since the array was allocated, say if it was reused for some other purpose in between. Also you probably should '#include <alloca.h>' which can be slightly annoying. .. _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/tinycc-devel