How to write spaghetti code in C++???

J

Joel Yliluoma

Obviously, this program outputs 1 3 6 4 7 6 2 3 6 4 7 6 0.

Except it doesn't. It outputs:
1
3
6
4
7
6
2
3
6
4
7
6

[No trailing 0].

Weird, it does output the trailing zero for me.

(What idiot came up with B_RETURN_TO? When would it possibly be useful?)

Spaghetti code is not spaghetti code without irregular execution paths.
B_RETURN_TO of course models the "RETURN <label>" statement in BASIC.
One such use for it would be for example, in a game where "GOSUB gamemain"
could be matched with a "RETURN" that asks for a new game and "RETURN endgame"
that cleans up and terminates.
It is a crude mechanism resembling function return values in languages
such as C++.
 
P

Philip Potter

Joel said:
Obviously, this program outputs 1 3 6 4 7 6 2 3 6 4 7 6 0.
Except it doesn't. It outputs:
1
3
6
4
7
6
2
3
6
4
7
6

[No trailing 0].

Weird, it does output the trailing zero for me.

Argh! I thought you were confusing the 'return 0;' with 'puts("0")'; I
didn't notice the puts("0") at the top which, confusingly, is the last
puts() called!
Spaghetti code is not spaghetti code without irregular execution paths.
B_RETURN_TO of course models the "RETURN <label>" statement in BASIC.

It doesn't exist in BBC BASIC, which is the variant I'm familiar with.
One such use for it would be for example, in a game where "GOSUB gamemain"
could be matched with a "RETURN" that asks for a new game and "RETURN endgame"
that cleans up and terminates.
It is a crude mechanism resembling function return values in languages
such as C++.

Oh. That kinda sorta makes some sense...
 
J

Juha Nieminen

Philip said:
Argh! I thought you were confusing the 'return 0;' with 'puts("0")'; I
didn't notice the puts("0") at the top which, confusingly, is the last
puts() called!

That's what makes it such beautiful spaghetti code... :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top