Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > global goto in c

Reply
Thread Tools

global goto in c

 
 
fir
Guest
Posts: n/a
 
      06-06-2013
W dniu czwartek, 6 czerwca 2013 14:30:14 UTC+2 użytkownik Johann Klammer napisał:
> fir wrote:
>
> > W dniu czwartek, 6 czerwca 2013 11:37:39 UTC+2 użytkownik Xavier Roche napisał:

>
> >> On 06/06/2013 11:29 AM, fir wrote:

>
> >>

>
> >>> no, like

>
> >>

>
> >>>

>
> >>

>
> >>> e()

>
> >>

>
> >>> {

>
> >>

>
> >>> label:

>
> >>

>
> >>>

>
> >>

>
> >>> }

>
> >>

>
> >>>

>
> >>

>
> >>> main()

>
> >>

>
> >>> {

>
> >>

>
> >>> goto(label); //label is any label in any function

>
> >>

>
> >>>

>
> >>

>
> >>> }

>
> >>

>
> >>

>
> >>

>
> >> Short answer: no. Entering in another function or inside a block require

>
> >>

>
> >> to have some stack/heap initialization, and this is just not possible.

>
> >>

>
> >> setjmp/longjmp tricks may be used, but only to rollback from a given

>
> >>

>
> >> point (ie. going back in a context deeper in the stack has a totally

>
> >>

>
> >> undefined behavior - correct me if I am wrong)

>
> >

>
> > you do not need to use stack variables

>
> > just

>
> >

>
> > f()

>
> > {

>
> >

>
> > f1_label:

>
> >

>
> > // some code

>
> >

>
> > goto(main1_label);

>
> >

>
> > }

>
> >

>
> > main()

>
> > [

>
> > goto(f1_label);

>
> > //some code

>
> >

>
> > main1_label:

>
> > }

>
> >

>
> > should probably work, but i am not sure

>
> > as to casting labels on void* and then

>
> > passing this to assembly

>
>
>
> Yes, that'll probably work, but why the function, then?
>
> You cannot use it for return, because the return address is not on stack
>
> frame and base ptr etc are all wrong... it would jump to nirvana... If
>
> you are trying to set up something coroutine like, you'll want to look
>
> at POSIX' ucontext.h. It's available on most unices and similar
>
> functionality can often be hacked up on other OSs.


indeed it was in the context of the coroutine
stuff (where it could help to write/implement
such coroutines in c I think, but do not matter)
 
Reply With Quote
 
 
 
 
Mark Storkamp
Guest
Posts: n/a
 
      06-06-2013
In article <(E-Mail Removed)>,
fir <(E-Mail Removed)> wrote:

> W dniu czwartek, 6 czerwca 2013 11:37:39 UTC+2 uytkownik Xavier Roche
> napisa:
> > On 06/06/2013 11:29 AM, fir wrote:
> >
> > > no, like

> >
> > >

> >
> > > e()

> >
> > > {

> >
> > > label:

> >
> > >

> >
> > > }

> >
> > >

> >
> > > main()

> >
> > > {

> >
> > > goto(label); //label is any label in any function

> >
> > >

> >
> > > }

> >
> >
> >
> > Short answer: no. Entering in another function or inside a block require
> >
> > to have some stack/heap initialization, and this is just not possible.
> >
> > setjmp/longjmp tricks may be used, but only to rollback from a given
> >
> > point (ie. going back in a context deeper in the stack has a totally
> >
> > undefined behavior - correct me if I am wrong)

>
> you do not need to use stack variables
> just
>
> f()
> {
>
> f1_label:
>
> // some code
>
> goto(main1_label);
>
> }
>
> main()
> [
> goto(f1_label);
> //some code
>
> main1_label:
> }
>
> should probably work, but i am not sure
> as to casting labels on void* and then
> passing this to assembly


If f() contained any local variables, you wouldn't be able to use them
since the stack frame hasn't been set up. (and let's please not go down
the rabbit hole of c not requiring a stack). So you might just as well
make the code between f1_label: and the goto into a function of its own,
and call it from both main and from f(). Perhaps you can even inline it.
 
Reply With Quote
 
 
 
 
Noob
Guest
Posts: n/a
 
      06-06-2013
Eric Sosman wrote:

> Out of curiosity: What subject do you teach, Professor?


Isn't it obvious? He teaches (us) the art of trolling.

Regards.

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-06-2013
On 6/6/2013 11:02 AM, Noob wrote:
> Eric Sosman wrote:
>
>> Out of curiosity: What subject do you teach, Professor?

>
> Isn't it obvious? He teaches (us) the art of trolling.


You'll notice that he responded to my question, but
did not answer it.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      06-06-2013
On Thu, 2013-06-06, fir wrote:
> W dniu czwartek, 6 czerwca 2013 14:30:14 UTC+2 u??ytkownik Johann Klammer napisa??:
>> fir wrote:
>>
>> > W dniu czwartek, 6 czerwca 2013 11:37:39 UTC+2 u??ytkownik Xavier Roche napisa??:

>>
>> >> On 06/06/2013 11:29 AM, fir wrote:

>>
>> >>

>>
>> >>> no, like

>>
>> >>

>>
>> >>>

>>
>> >>

>>
>> >>> e()

>>
>> >>

>>
>> >>> {

>>
>> >>

>>
>> >>> label:


Please fix your newsreader. Seriously.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      06-06-2013
Mark Storkamp <(E-Mail Removed)> wrote:
> In article <(E-Mail Removed)>,
> fir <(E-Mail Removed)> wrote:


(snip)
>> > > goto(label); //label is any label in any function
>> > Short answer: no. Entering in another function or inside a block require
>> > to have some stack/heap initialization, and this is just not possible.
>> > setjmp/longjmp tricks may be used, but only to rollback from a given
>> > point (ie. going back in a context deeper in the stack has a totally
>> > undefined behavior - correct me if I am wrong)


Seems right to me. PL/I has LABEL variables and a global GOTO
using them, but again, you can only go back in the call tree.

The last (and maybe only) time I rememeber using longjmp() was for
a translation of a Pascal program that used a global GOTO.
(I believe to go out of an internal procedure.)

>> you do not need to use stack variables just


(snip)
>> should probably work, but i am not sure
>> as to casting labels on void* and then
>> passing this to assembly


It might have a chance in Fortran 66, where there is no recursion,
all variables are static (in most implementations) but not in any
language allowing recursion.

> If f() contained any local variables, you wouldn't be able to use them
> since the stack frame hasn't been set up. (and let's please not go down
> the rabbit hole of c not requiring a stack). So you might just as well
> make the code between f1_label: and the goto into a function of its own,
> and call it from both main and from f(). Perhaps you can even inline it.


Yes, PL/I, in the IBM implementations uses a linked list instead of
a (physical) stack, but it is logically a stack. The library routines
that handle global GOTO know how to undo what needs to be undone,
and to report an error for illegal GOTOs.

I believe both longjmp() and PL/I GOTO know about recursion, and
return to the appropriate instance of a recursive procedure.

-- glen
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-06-2013
Jorgen Grahn <(E-Mail Removed)> writes:
> On Thu, 2013-06-06, fir wrote:
>> W dniu czwartek, 6 czerwca 2013 14:30:14 UTC+2 u??ytkownik Johann Klammer napisa??:
>>> fir wrote:
>>>
>>> > W dniu czwartek, 6 czerwca 2013 11:37:39 UTC+2 u??ytkownik Xavier Roche napisa??:
>>>
>>> >> On 06/06/2013 11:29 AM, fir wrote:
>>>
>>> >>
>>>
>>> >>> no, like
>>>
>>> >>
>>>
>>> >>>
>>>
>>> >>
>>>
>>> >>> e()
>>>
>>> >>
>>>
>>> >>> {
>>>
>>> >>
>>>
>>> >>> label:

>
> Please fix your newsreader. Seriously.


It's not his newsreader; the problem is that he's not using one.

groups.google.com causes this problem. In articles posted via Google
Groups, each quoted line (introduced by "> ") is treated as a
*paragraph*. This results in quoted text being double-spaced, then
quadruple-spaced, etc.

This probably works ok for Google's own web-based groups, but clearly
Google's convention interacts poorly with the plain-text posts produced
by most uses of NNTP newsreaders. Google has shown no signs of caring
about this problem.

fir, if you copy-and-paste your articles into a text editor, manually
edit them, and then copy them back into your browser before posting, it
*might* alleviate the problem. Better yet, get an account on a free or
cheap NNTP server (I use news.eternal-september.org) and use an
NNTP-based client program (Mozilla Thunderbird can do this).

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      06-06-2013
W dniu czwartek, 6 czerwca 2013 19:45:06 UTC+2 użytkownik Keith Thompson napisał:
>
>
> It's not his newsreader; the problem is that he's not using one.
> groups.google.com causes this problem. In articles posted via Google
> Groups, each quoted line (introduced by "> ") is treated as a
> *paragraph*. This results in quoted text being double-spaced, then
> quadruple-spaced, etc.
>
>
>
> This probably works ok for Google's own web-based groups, but clearly
> Google's convention interacts poorly with the plain-text posts produced
> by most uses of NNTP newsreaders. Google has shown no signs of caring
> about this problem.
>
>
>
> fir, if you copy-and-paste your articles into a text editor, manually
> edit them, and then copy them back into your browser before posting, it
> *might* alleviate the problem. Better yet, get an account on a free or
> cheap NNTP server (I use news.eternal-september.org) and use an
> NNTP-based client program (Mozilla Thunderbird can do this).
>


ye, thats google groups,
The best would be if they would repair it
(most of the time i prefer just to dont care
;(
Tried some newsreaders but dislike them, some
www usenet news gate could be good but i do
not know one (must be free - i was trying narkive but something did not work, i couldnt
register)
Besides I am searching for some good usenet
group about programming games and algorithms/
ways of programming things (in c) is there
some alive and reasonably good (some specialist onboard) usenet group for that?

fir
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      06-06-2013
W dniu czwartek, 6 czerwca 2013 21:17:33 UTC+2 użytkownik Scott Fluhrer napisał:
> "fir" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> W dniu czwartek, 6 czerwca 2013 14:28:12 UTC+2 uzytkownik Bart napisal:
>
> >>

>
> >>

>
> >> It is possible to assign that label address to a file-scope variable, and

>
> >> attempt to 'goto' that address from another function, but it will likely

>
> >> crash because of other considerations. It will in any case need tricky

>
> >> setup

>
> >> of those addresses.

>
> >

>
> >

>
> > If so it is damn sad, i think this label

>
> > adresses could be avaliable/accesible.

>
>
>
> Why, what could you usefully do the label address (apart from jumping to it
>
> within the same routine)?
>
>
>
> Suppose you do just from function A() to a label in function B(). Then:
>
>
>
> - What values do you expect that the local variables in B to have?
>
>
>
> - What do you expect to happen if function B returns?
>
>
>
> If you say that, in your problem space, you don't care about either of these
>
> questions, then I would respond that your problem space is too small to
>
> place this potential rake-in-the-grass feature into C; people would expect
>
> reasonable answers to the above questions, and we can't provide them.
>
>
>
> You mention coroutines; I believe that most coroutines have local variables
>
> that are expected to be preserved when the coroutine resumes; how would that
>
> work in your design?
>


In, say, 'most' cases goto do not need passing values
on stack. in some cases it even can do it :
lets say that a 'block' has
five entry-for-goto points, and three
exit-goto points; Entry goto pushes n bytes
of arguments then exit goto clears this
n bytes at exit - It could even be combined
with standard call-entry-point (clear it
before ret, maybe you will need to pass
values of n bytes to clear on exit goto and
m balues to clear on ret encounter or
something like this - it could be done
in some ways. As to usability i do not know
but maybe it could be usefull for something.
 
Reply With Quote
 
fir
Guest
Posts: n/a
 
      06-06-2013
W dniu czwartek, 6 czerwca 2013 20:02:52 UTC+2 użytkownik David Harmonnapisał:
>
> Google "GOTO considered harmful"


sure, I totally do not know whot would be
the outcome of such global-goto programming
(does anybody know?) the classic procedural
way is enough complex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
VHDL Goto statement ? Skybuck Flying VHDL 9 08-26-2005 01:46 PM
Re: VHDL Goto statement ? Skybuck Flying VHDL 0 08-08-2005 03:21 AM
goto statement is recommened in systemc? youngsun park VHDL 2 11-18-2003 03:47 PM



Advertisments