for is way faster than goto in C?
Go to solution
Solved by Eigenvektor,
28 minutes ago, Gat Pelsinger said:Isn't it doing exactly the same thing as the for loop?
Logically? Yes. But the compiler doesn't know that.
When you use a for-loop, the compiler knows you're writing a loop, so it can make certain assumptions/optimizations right away. If you use goto, all it knows is that you're jumping somewhere under certain conditions. It can't know that this is intended to be a loop. If you do enable optimization, it'll perform additional analysis and likely arrive at the same result. Without optimization it just performs a literal translation of C to assembler.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now