Jump to content

Over-optimization Using Goto?


Recommended Posts

I have generated the following test-case which demonstrates something that I ran into:

#include <system.h>

void main()
{
char a=0;
while(1) {
	a|=portb;
	if(test_bit(a,0))
		goto reset;
	if(0) {
reset:
		a=0;
	}
	a<<=1;
}
}

When I compile this, it compiles fine, but the linker reports:

Internal Error: Unable to resolve label ID:0x1000024B

apparently, the 'if(0)' is getting optimized out, so the goto fails.

I am using code like this in an interrupt routine to reset a state-machine on bad input

 

of course, I can write the code as:

#include <system.h>

void main()
{
char a=0;
while(1) {
	a|=portb;
	if(test_bit(a,0))
		goto reset;
	goto cont;
reset:
		a=0;
cont:
	a<<=1;
}
}

and I'd expect the output assembly to be identical, but as far as I know the 1st method is valid C syntax, and should work correctly.

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...