M
Man with Oscilloscope
goto jumping over vla -- diagnostic required?
This is a question about C99, 6.8.6.1, example 2 (see test below).
I'm currently working on updating an older compiler up to C99. The
standard is very clear about jumping into and out of the middle of
a block declaring variably modified types. The example below,
however, just jumps over the actual VLA declaration, within the
/same/ block. A quick test with two different compilers claiming
(at least partial) C99 conformance reveals...
The lcc-win32 compiler (tested with version 3.8) accepts it without
any diagnostics, but generates unusable code (more specifically,
the `goto' jumps past the instructions necessary to set up space
for `vla[]').
Gcc (all version with (partial) C99 support), on the other hand,
reject the example with a hard error.
What is the best course of action here? Is this an example of
"everone who writes such code deserved what they get", or is a
strictly conforming compiler required to reject it?
--8<---------------------------------------------------------------
/*
* vlatest.c
*
* gcc -Wall -W -O2 -std=c99 vlatest.c -o vlatest
* ("vlatest.c:26: error: label `bar' used before \
* containing binding contour")
*
* lc -A -O -ansi -unused vlatest.c
* (no diagnostic printed, invalid executable generated, BOOM!)
*/
#include <stdio.h>
#include <string.h>
int foo = 1;
void vlatest(size_t size)
{
printf("vlatest...\n");
if(foo)
goto bar;
int vla[size];
bar:
memset(vla, 0xCC, sizeof vla);
printf("BAMM!!!\n");
}
int main(void)
{
vlatest(1024);
return 0;
}
--8<---------------------------------------------------------------
This is a question about C99, 6.8.6.1, example 2 (see test below).
I'm currently working on updating an older compiler up to C99. The
standard is very clear about jumping into and out of the middle of
a block declaring variably modified types. The example below,
however, just jumps over the actual VLA declaration, within the
/same/ block. A quick test with two different compilers claiming
(at least partial) C99 conformance reveals...
The lcc-win32 compiler (tested with version 3.8) accepts it without
any diagnostics, but generates unusable code (more specifically,
the `goto' jumps past the instructions necessary to set up space
for `vla[]').
Gcc (all version with (partial) C99 support), on the other hand,
reject the example with a hard error.
What is the best course of action here? Is this an example of
"everone who writes such code deserved what they get", or is a
strictly conforming compiler required to reject it?
--8<---------------------------------------------------------------
/*
* vlatest.c
*
* gcc -Wall -W -O2 -std=c99 vlatest.c -o vlatest
* ("vlatest.c:26: error: label `bar' used before \
* containing binding contour")
*
* lc -A -O -ansi -unused vlatest.c
* (no diagnostic printed, invalid executable generated, BOOM!)
*/
#include <stdio.h>
#include <string.h>
int foo = 1;
void vlatest(size_t size)
{
printf("vlatest...\n");
if(foo)
goto bar;
int vla[size];
bar:
memset(vla, 0xCC, sizeof vla);
printf("BAMM!!!\n");
}
int main(void)
{
vlatest(1024);
return 0;
}
--8<---------------------------------------------------------------