|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Fredrik Eriksson a écrit :
> On Thu, 24 Jul 2008 14:24:51 +0200, Vincent Le Chevalier
> <gal### [at] libertyallsurfspamfr> wrote:
>> Here's what I ended up with:
> [...snipped...]
>
> The "right" way to do it, assuming C++:
> http://www.gotw.ca/gotw/057.htm
>
Thanks for that!
--
Vincent
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible <voi### [at] devnull> wrote:
> More exactly: It's a workaround for C's lack of lack of GOTO.
Except that C does have goto.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Chris Cason <del### [at] deletethistoopovrayorg> wrote:
> Of course, this being C, 'TRUE' could be a macro that expands to a function
> that returns a value and thus the loop need not be infinite.
Actually there are other ways for the loop to end. For instance, the
function being called could execute an exit() call.
(Another less fancy way would be to return a null pointer from the
function, in which case the program will end with a segmentation fault.)
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> More exactly: It's a workaround for C's lack of lack of GOTO.
>
> Except that C does have goto.
Ooo, really?
In that case, I have *no clue* why they did it this way...
Oh, wait, maybe I do... Can you use GOTO to jump to a *pointer*? Or only
a literal label?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Actually there are other ways for the loop to end. For instance, the
> function being called could execute an exit() call.
I believe that is in fact what's meant to happen, yes.
> (Another less fancy way would be to return a null pointer from the
> function, in which case the program will end with a segmentation fault.)
...or have count() perform any other illegal program-halting action.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible <voi### [at] devnull> wrote:
> >> More exactly: It's a workaround for C's lack of lack of GOTO.
> >
> > Except that C does have goto.
> Ooo, really?
> In that case, I have *no clue* why they did it this way...
Because "while(1)" is a common idiom, and avoids the ugly goto.
> Oh, wait, maybe I do... Can you use GOTO to jump to a *pointer*? Or only
> a literal label?
Jumping to a pointer is normally called "function call".
Goto works only with labels.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>>> Except that C does have goto.
>
>> Ooo, really?
>
>> In that case, I have *no clue* why they did it this way...
>
> Because "while(1)" is a common idiom, and avoids the ugly goto.
>
>> Oh, wait, maybe I do... Can you use GOTO to jump to a *pointer*? Or only
>> a literal label?
>
> Jumping to a pointer is normally called "function call".
>
> Goto works only with labels.
Yes, but jumping to a function pushes a return address onto the stack.
And they specifically don't want to do that. (Because it would use an
unbounded amount of stack.)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible <voi### [at] devnull> wrote:
> Yes, but jumping to a function pushes a return address onto the stack.
> And they specifically don't want to do that. (Because it would use an
> unbounded amount of stack.)
Functions in C don't need to return anything.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Invisible <voi### [at] devnull> wrote:
>> More exactly: It's a workaround for C's lack of lack of GOTO.
>
> Except that C does have goto.
I thought that's what "lack of lack of GOTO" meant.<G>
--
I almost had a psychic girlfriend, but she left me before I met her.
/\ /\ /\ /
/ \/ \ u e e n / \/ a w a z
>>>>>>mue### [at] nawazorg<<<<<<
anl
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> Yes, but jumping to a function pushes a return address onto the stack.
>> And they specifically don't want to do that. (Because it would use an
>> unbounded amount of stack.)
>
> Functions in C don't need to return anything.
The idea here is that we jump to one label, then jump to another, then
jump to another, never returning to the "caller".
If we implement this using C functions that never return, an unbounded
amount of stack gets eaten.
Hence, they arranged for each function to *return* the function it would
like to jump to next, rather than actually jumping to it, and the loop I
posted is apparently the magic incantation that implements the jumping.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |