473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

about goto

Hi,
I got this code from some site:

#include <stdio.h>
int
main() {
int n = -1;
x0:
printf("%d\n" , ++n);
goto *(&&x0 + n/1000 * (&&x1 - &&x0));
x1:
return 0;
}

it doesnt compile successfully. Apparently the goto statement need a
hardcoded *label* for a correct compilation. The above code maybe written in
gcc i think. Am i right to say that this code cannot compile in vc?

regards,
...ab
Mar 6 '08 #1
2 1077

"Abubakar" <q@y.comwrote in message
news:eO*************@TK2MSFTNGP02.phx.gbl...
Hi,
I got this code from some site:

#include <stdio.h>
int
main() {
int n = -1;
x0:
printf("%d\n" , ++n);
goto *(&&x0 + n/1000 * (&&x1 - &&x0));
x1:
return 0;
}

it doesnt compile successfully. Apparently the goto statement need a
hardcoded *label* for a correct compilation. The above code maybe written
in gcc i think. Am i right to say that this code cannot compile in vc?
Neither C nor C++ allow computed goto. Computed goto may have some
performance advantages over naive control structures, but the optimizing
compiler should generate code at least as fast as computed goto.
>
regards,
..ab

Mar 6 '08 #2

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
"Abubakar" <q@y.comwrote in message
news:eO*************@TK2MSFTNGP02.phx.gbl...
>Hi,
I got this code from some site:

#include <stdio.h>
int
main() {
int n = -1;
x0:
printf("%d\n" , ++n);
goto *(&&x0 + n/1000 * (&&x1 - &&x0));
x1:
return 0;
}

it doesnt compile successfully. Apparently the goto statement need a
hardcoded *label* for a correct compilation. The above code maybe written
in gcc i think. Am i right to say that this code cannot compile in vc?

Neither C nor C++ allow computed goto. Computed goto may have some
performance advantages over naive control structures, but the optimizing
compiler should generate code at least as fast as computed goto.
Also note that an array of function pointers is possible in C (or C++), and
provides a computed gosub.
>
>>
regards,
..ab


Mar 6 '08 #3

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

Similar topics

39
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am...
30
by: Hayri ERDENER | last post by:
hi, what is the equivalent of C languages' goto statement in python? best regards
11
by: Capstar | last post by:
Hi, I am working on an application, which will run embedded without an OS. The app is build up out of a couple of well defined parts. At first I wanted to keep those parts seperated and use...
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
53
by: jaso | last post by:
Can you give any comments on this code? I used one goto, is it bad? #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <assert.h> #define NOT_NULL 1
17
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.