[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Tinycc-devel] Best workaround for VLA's

From: Christian Jullien
Subject: RE: [Tinycc-devel] Best workaround for VLA's
Date: Fri, 8 Apr 2011 08:41:47 +0200

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: address@hidden
[mailto:address@hidden On Behalf Of Joe
Sent: vendredi 8 avril 2011 08:33
To: address@hidden
Subject: Re: [Tinycc-devel] Best workaround for VLA's

On Thu, Apr 7, 2011 at 9:50 PM, Luis Alejandro Muzzachiodi
<address@hidden> 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
> 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.

    char str[i+15];
    float flt[veclen];
    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
    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]) { /*
... */ }

    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


Tinycc-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]