473,765 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VLA and goto -- diagnostic required?


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<---------------------------------------------------------------

--
mwo, Researcher

Aug 24 '06 #1
8 2497
What the lcc-win32 compiler is concerned there is no BAAM at all.

It crashes without ever arriving at your printf("BAMM");
statement :-)

The reason is that I store the size of the array together with its
initialization in a local hidden variable that I setup at the moment
of the allocation of the stack space. Since you have skipped
the initialization of the sizeof variable, you are pushing a semi
random value into the memset... what makes probably for a big
stack overflow. Since stack overflow is not catched in the
runtime (I can't even make some space for the printing of some
abort message) the program ends abruptly...

I hope this is correct :-)

I am not a language lawyer, and in lcc-win32 implementation not all
possible errors are catched.

Now that you have done this, maybe I will find time I will try to catch
this. I have to:

1) In all functions that use VLA
2) Test if there is a goto statement that could potentially
skip a VLA initialization routine.

That point (2) is not at all evident to catch without a full blown
flow control analysis, what lcc-win32 doesn't have.

I have tried till now to keep the compiler simple. I will see how can
I do this in some evident cases as the one you posted but the general
case would be too expensive (in developing time and in compiler
complexity). Please compare the gcc team (more than 30-40 people
full time, with big ncompanies like IBM behind it) and the
lcc-win32 team of just two people.

jacob

Aug 24 '06 #2
The standard does not specify that a diagnostic is required in this
case.

The wording is:

EXAMPLE 2 A goto statement is not allowed to jump past any declarations
of objects with variably modified types. A jump within the scope,
however, is permitted.
goto lab3; // invalid: going INTO scope of VLA.
{
double a[n];
a[j] = 4.4;
lab3:
a[j] = 3.3;
goto lab4; // valid: going WITHIN scope of VLA.
a[j] = 5.5;
lab4:
a[j] = 6.6;
}
goto lab4; // invalid: going INTO scope of VLA.

Maybe a language lawyer could help us here. If a diagnostic is required
I will issue a diagnostic of course and this is a bug in lcc-win32 that
will be corrected no matter what.

jacob
Aug 24 '06 #3
Man with Oscilloscope wrote:
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;
}
Here is the relevant constraint from the Standard:
"A goto statement shall not jump from outside the scope of an
identifier having a variably modified type to inside the scope of that
identifier."

Note carefully the wording: "from outside the scope ... to inside the
scope". The scope of vla begins immediately after its declaration and
ends at the end of the function vlatest. Your example jumps from
outside the scope of vla to inside the scope of vla. That is a
constraint violation requiring the issue of a diagnostic.

Robert Gamble

Aug 24 '06 #4
if(foo)
goto bar;
LOL!!!

Aug 30 '06 #5
la****@linuxmai l.org wrote:
if(foo)
goto bar;

LOL!!!
I have always wondered what LOL stands for.
And what does it do in this context.

Look Out Lanius... :-)


Aug 30 '06 #6
jacob navia wrote:
la****@linuxmai l.org wrote:
>
> if(foo)
goto bar;

LOL!!!

I have always wondered what LOL stands for.
And what does it do in this context.
Laughing out loud.

--
Chuck F (cb********@yah oo.com) (cb********@mai neline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.netUSE maineline address!

Aug 30 '06 #7
CBFalconer wrote:
jacob navia wrote:
>>la****@linuxm ail.org wrote:

>>>
>> if(foo)
goto bar;

LOL!!!

I have always wondered what LOL stands for.
And what does it do in this context.


Laughing out loud.
Ahhhh
Thanks Chuck, that WAS helpful.

My daughter told me she uses it but she could not tell me
what that stands for.

Nor my son, nor several other teens I asked. Most of them
know what it "means" and know how to use it but none
could tell me where that came from or what that means.

One of the teens told me it is better to use the french
MDR (Mort De Rire or "laughing to death" but those sentences are
untranslateable anyway)

jacob
Aug 30 '06 #8
jacob navia <ja***@jacob.re mcomp.frwrote:
Thanks Chuck, that WAS helpful.
Perhaps you might also find this useful:

http://www.answers.com/topic/lol-internet-slang

I would claim to be LMAO, but that's not realistic in terms of office
decorum.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gma il.com | don't, I need to know. Flames welcome.
Aug 30 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1224
by: Christopher Benson-Manica | last post by:
Is a conforming C++ implementation required to issue a diagnostic when invoked on the following code? #include <cstdlib> #include <iostream> #include <string> int main() { printf( "Hello, world!\n" ); // oops, <cstdio> missing
45
2726
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. -- http://www.kashmiri-pandit.org/atrocities/index.html
17
2316
by: Mike Hofer | last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my principal language has been BASIC, QBASIC, then Visual Basic, and finally Visual Basic .NET. But lately, I've been using C# and I absolutely *love* it. It makes me think more about what I'm doing it before I just spew code into the editor. I'm writing better code than ever. The only thing so far that I don't like about it is the switch construct. I can't do this:
34
26646
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
2
1976
by: miaohua1982 | last post by:
under the same warning level, the code is: class X{ public: X(){} virtual void g(){} }; void f(int i){ if(i<10) goto jump1;
41
3017
by: p_cricket_guy | last post by:
Please see this test program: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <limits.h> 4 5 int main (void) 6 { 7 int y = -2147483648; 8 int x = INT_MIN;
11
2524
by: Old Wolf | last post by:
Does the following program require a diagnostic? Which section of the Standard deals with this? (I read the section on function calls and didn't see anything). void f(void); int main(void) { f(); } Is the answer still the same if the function declaration was: static void f(void);
11
3415
by: =?Utf-8?B?Um9nZXIgVHJhbmNoZXo=?= | last post by:
Hello, I have a question about the infamous GOTO statement and the way to return a result from a sub: I have a sub that has to make some calls to external COM methods, and because these methods can fail I have to check them to be running ok, like this:
5
1700
by: santosh | last post by:
We are given the definition of a "diagnostic message" in 3.10 of the Standard. To quote: 3.10 1 diagnostic message message belonging to an implementation-defined subset of the implementation's message output Unless I'm mistaken, (which I probably am), the definition clearly implies that each conforming implementation must clearly distinguish
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.