blank
blank

Reputation: 18170

Will 30 GOTO 10 always go to 10?

In the spirit of the latest podcast where Joel mentioned he'd like some simple questions with possibly interesting answers ...

In the environments we have to programme in today we can't rely on the order of execution of our langauage statements. Is that true? Should we be concerned?

Will 30 GOTO 10 always go to 10?*

*I didn't use 20 on purpose ;)

[edit] for the four people voting for closure of this question ...

"Runtime compilers use profiling information to help optimize the code being compiled. The JVM is permitted to use information specific to the execution in order to produce better code, which means that the compiling method M in one program may generate different code than compiling M in another"

(from Java concurrency in practice, 2006, Goetz et al)

.. have a look at "monomorphic call transformation"

[edit]

and another edit, your processor is allowed to swap the order of execution of statements ...

Upvotes: 1

Views: 1200

Answers (7)

devio
devio

Reputation: 37215

True, if you consider multi-core CPUs executing a BASIC program, one of the cores might accidentally miss the GOTO (hint: "TLB Bug") and continue as if it weren't there.

Upvotes: 0

DJ.
DJ.

Reputation: 1025

alt text

Upvotes: 8

Tomas Aschan
Tomas Aschan

Reputation: 60664

What are you trying to say? Anyone claiming to be a programmer should know (especially after your hint) that it depends on what's on lines 10 and 20, and anyone who's been on SO for longer than a week should realize that this question doesn't seem to add much.

We should rely on the code doing exactly what we tell it to. If we tell it to GOTO 10 on line 30, but also tell it to skip line 30, we shouldn't be the least surprise when line 30 is skipped. We told the program to.

Upvotes: 0

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 248159

No, it will not. But it will always behave as if it did. One of the basic rules in compiler design is the "as if" rule. Your compiler can make whatever changes it likes, as long as the result is going to behave as if you'd followed the language rules.

GOTO 10 may decide to jump to some other location, as long as the compiler can guarantee that it won't change the outcome of the program.

So no, it shouldn't worry you.

Upvotes: 25

Yes - that Jake.
Yes - that Jake.

Reputation: 17119

In BASIC, yes. In other languages, it will generate a compile error.

Upvotes: 1

Paul Sonier
Paul Sonier

Reputation: 39510

Well, it won't if it doesn't execute, for example if there's a 20 GOTO 40.

Upvotes: 1

Joachim Sauer
Joachim Sauer

Reputation: 308151

Not if you've got

40 COMEFROM 30

somewhere in your code.

Upvotes: 13

Related Questions