473,473 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Compilation Error?

Consider the following code snippet..

#include<iostream>
using namespace std;

int func(void);

int main() {
cout<<"Result :"<<func()<<endl;
}

int func (void) {
int result = 0;
if (true) {
result = 1;
goto cleaup:

}

int i = 0; // i initialize a dummy here.. Error in XCode or Gcc !

cleanup:
return (result);
}

If i compile the above code with Visual Studio 6.0 compiler or
CodeWarrior (Mac) it compiles without any error, but if i compile this
code using gcc or XCode (Mac) it gives the following error..
error: jump to label 'cleanup'
error: from here
error: crosses initialization of 'int i'

The only way to solve this problem is to move the 'int i' definition
below the 'int result' definition... is there any other way??

May 10 '06 #1
4 3040
vi********@gmail.com wrote:
Consider the following code snippet..

#include<iostream>
using namespace std;

int func(void);

int main() {
cout<<"Result :"<<func()<<endl;
}

int func (void) {
int result = 0;
if (true) {
result = 1;
goto cleaup:

}

int i = 0; // i initialize a dummy here.. Error in XCode or Gcc !

cleanup:
return (result);
}

If i compile the above code with Visual Studio 6.0 compiler or
CodeWarrior (Mac) it compiles without any error, but if i compile this
code using gcc or XCode (Mac) it gives the following error..
error: jump to label 'cleanup'
error: from here
error: crosses initialization of 'int i'
"It is possible to transfer into a block, but not in a way that
bypasses declarations with initialization. A program that jumps from a
point where a local variable with automatic storage duration is not in
scope to a point where it is in scope is ill-formed unless the variable
has POD type (3.9) and is declared without an initializer (8.5)."
(6.7§3)
The only way to solve this problem is to move the 'int i' definition
below the 'int result' definition... is there any other way??


Don't use goto?
Jonathan

May 10 '06 #2
vi********@gmail.com wrote:
Consider the following code snippet..

#include<iostream>
using namespace std;

int func(void);

int main() {
cout<<"Result :"<<func()<<endl;
}

int func (void) {
int result = 0;
if (true) {
result = 1;
goto cleaup:

}

int i = 0; // i initialize a dummy here.. Error in XCode or Gcc !

cleanup:
return (result);
}

If i compile the above code with Visual Studio 6.0 compiler or
CodeWarrior (Mac) it compiles without any error, but if i compile this
code using gcc or XCode (Mac) it gives the following error..
error: jump to label 'cleanup'
error: from here
error: crosses initialization of 'int i'
I'm surprised this compiles with any compiler.
The only way to solve this problem is to move the 'int i' definition
below the 'int result' definition... is there any other way??

Sack whoever wrote this rubbish.

--
Ian Collins.
May 10 '06 #3
Raj

it shudnt have worked with any of the compiler as far as myknowledge is
concerned.. try the latest compiler version n u'll catch the error..
the only workout is : goto is a bad practice.. stop using it..

May 10 '06 #4
Raj wrote:
it shudnt have worked with any of the compiler as far as myknowledge is
concerned.. try the latest compiler version n u'll catch the error..
the only workout is : goto is a bad practice.. stop using it..

Are you answering me or the OP?

Please quote context (see <http://cfaj.freeshell.org/google/>) in your
replies and avoid txt speak.

--
Ian Collins.
May 10 '06 #5

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

Similar topics

4
by: konf | last post by:
Hallo, I tried to compile PGSQL 7.4 and I got error (durring make): ar: command not found What is it? Whe I can found it? I have: $ uname -a SunOS ... 5.8 Generic_108528-03 sun4u sparc...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
6
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application....
2
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while...
0
by: James Zhuo | last post by:
hi all I changed the name of the class LoginPage to a different name "LoginPageOne" But the same error gets generated with the Wiliam.Request.LoginPageOne. That pretty much leaves me clueless...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
6
by: Plat | last post by:
I've Googled this for a while, to no avail. Hopefully someone can help me. Maybe I'm using the wrong terminology. Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax...
3
by: Robert | last post by:
I have a number of web projects converted from 1.1 to 2.0 in VS2005. I am methodically seeing the error below: The element 'compilation' has invalid child element 'compilers'. List of...
0
by: Stimp | last post by:
I've created an aspx page called HistoryManage.aspx. The page works fine on my local machine but when I load it off the web I get the following strange error... Compilation Error...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.