GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Dec-2008, 18:34
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Bool Confusion


i have this function to determine the operand precedence
CPP / C++ / C Code:
bool op_precedence(char a, char b)
{
return(a=='*'||a=='/')>=(b=='*'||b=='/');
}
can nayone tell me how the compiler will evaluate this expression when
1 - a=='+' and b=='*'
2- a=='*' and b=='/'

thanks all.
  #2  
Old 09-Dec-2008, 21:35
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Bool Confusion


Quote:
Originally Posted by zatora
i have this function to determine the operand precedence
CPP / C++ / C Code:
bool op_precedence(char a, char b)
{
return(a=='*'||a=='/')>=(b=='*'||b=='/');
}
can nayone tell me how the compiler will evaluate this expression when
1 - a=='+' and b=='*'
2- a=='*' and b=='/'

thanks all.
Code:
a = '-' b = '/' (yes I know this was not one of your questions, but I won't give you the answer. With this info, you can figure out the answers for your yourself) return(a=='*'||a=='/')>=(b=='*'||b=='/'); \____/ \____/ \____/ \____/ F F F T \_______/ \_______/ F T \_________________/ ?
What do you expect to happen when comparing two binary values with >=?
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #3  
Old 09-Dec-2008, 22:22
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: Bool Confusion


well that looks not well formed and i have this function that i found online to determine the priority order between(*,+,/,-) and why the author put the code like that i have no idea , any better algorithm to compare the precedence order between those four operands. thanks all
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
bool problem in multi file format pfanning C++ Forum 6 08-Mar-2008 18:45
Drawing Program Max_Payne C++ Forum 13 23-Dec-2007 19:06
Help with some functions baka_yaro C++ Forum 3 14-Mar-2007 06:56
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 15:46
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:15.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.