Jump to content

Parentheses Problem


Recommended Posts

Hi,

 

Attempting to check for a bit in GPIO being set:

 

if( gpio & (1 << 5) == (1 << 5) )
{
set_bit(gpio, PIN_TRIAC); // bit is set
}
else
{	
clear_bit(gpio, PIN_TRIAC); // bit is clear
}

	if( gpio & (1 << 5) == (1<<5) )
002E  1C05	  BTFSS gbl_gpio,0
002F  2832	  GOTO	label268439188
0032		label268439188

	{
		set_bit(gpio, PIN_TRIAC);
0030  1505	  BSF gbl_gpio,2

	}
	else
0031  282E	  GOTO	label268439185

	{	
		clear_bit(gpio, PIN_TRIAC);
0032  1105	  BCF gbl_gpio,2

	}

 

 

This does not work, the code below does work as expected:

 

if( (gpio & (1 << 5)) == (1<<5) )
{
set_bit(gpio, 1);// bit is set

}
else
{	
clear_bit(gpio, 1);// bit is clear
}
	if( (gpio & (1 << 5)) == (1<<5) )
002E  3020	  MOVLW 0x20
002F  0505	  ANDWF gbl_gpio, W
0030  3A20	  XORLW 0x20
0031  1D03	  BTFSS STATUS,Z
0032  2835	  GOTO	label268439188
0035		label268439188

	{
		set_bit(gpio, PIN_TRIAC);
0033  1505	  BSF gbl_gpio,2

	}
	else
0034  282E	  GOTO	label268439185

	{	
		clear_bit(gpio, PIN_TRIAC);
0035  1105	  BCF gbl_gpio,2

	}

 

Is this a bug? Im using 12F683, and BoostC 6.81 - Everything on the left of the == operator should be evaluated as a whole, so the resultant should be the same in both cases, which by looking at the .casm files (when added to the project, this files gets placed in the source dir rather than the output dir, another bug?) the generated ASM is different??

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...