E
Erwin Lindemann
If a VLA appears within a loop body, it seems the behavior is
different with two different compilers I tried. I looked at the
standard text, but couldn't find a definite answer there either.
Consider the following test program
/* begin foo.c */
#include <stdio.h>
#include <string.h>
void test(int n, size_t size)
{
int i;
for(i = 0; i < n; i++) {
unsigned char vla[size];
memset(vla, (i & 255), size);
printf("step %d: vla=%p\n", i, &vla[0]);
}
}
int main(void)
{
test(10, 256*1024L);
return 0;
}
/* end foo.c */
With gcc, 'vla' is reused in every iteration, i.e., the address
of 'vla[0]' is identical in every step.
However, with lcc-win32, output is as follows...
step 0: vla=0x002ffea0
step 1: vla=0x002bfea0
step 2: vla=0x0027fea0
step 3: vla=0x0023fea0
[*CRASH*]
, meaning, new storage is allocated for 'vla' at every iteration,
eventually exhausting all available auto storage.
Now, is this just implementation dependant and this kind of construct
should be avoided, or is one of these compilers not working correctly?
Should a bug report be filed?
Thanks
different with two different compilers I tried. I looked at the
standard text, but couldn't find a definite answer there either.
Consider the following test program
/* begin foo.c */
#include <stdio.h>
#include <string.h>
void test(int n, size_t size)
{
int i;
for(i = 0; i < n; i++) {
unsigned char vla[size];
memset(vla, (i & 255), size);
printf("step %d: vla=%p\n", i, &vla[0]);
}
}
int main(void)
{
test(10, 256*1024L);
return 0;
}
/* end foo.c */
With gcc, 'vla' is reused in every iteration, i.e., the address
of 'vla[0]' is identical in every step.
However, with lcc-win32, output is as follows...
step 0: vla=0x002ffea0
step 1: vla=0x002bfea0
step 2: vla=0x0027fea0
step 3: vla=0x0023fea0
[*CRASH*]
, meaning, new storage is allocated for 'vla' at every iteration,
eventually exhausting all available auto storage.
Now, is this just implementation dependant and this kind of construct
should be avoided, or is one of these compilers not working correctly?
Should a bug report be filed?
Thanks