void InsertA(SET *A,int elem)
{
if( isMember(*A,elem) == false)
{
*A = *A || 1<<elem;; /*it says its in this row*/
}
}
/*Error: Lvalue required in Function InsertA
any thoughts on this guys? noob here
*/
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this statement :
We have these operators
*,=,||,<<Now look at the precedence table at
So lets see what happens:
1) Indirection will be performed first. There are two of them. They associate Right to Left. That means Right one will be performed first. Its important to understand that there are two dereferencing operator here which will be considered differently later when encountering the
=operator.2) A bit wise left shift will performed on 1.
3) A logical OR will be performed with
*Aand the result of bitwise shift. it may evaluate zero or non zero.4) This zero/nonzero value will be assigned to
*A. Here*Acan be treated as lvalue in a context of=operator. If you leave this consideration it will lead to ambiguity. Because we often think of dereferencing operation like*Aas anrvalueor anvalueto be used. Actually its a validlvaluewhich will be converted implicitly to arvalue(This is when avaluewhich is stored at address pointed byAis returned). Otherwise*Ais simply a container in memory which is open to values.So the thing is your expression is undefined and does not make any sense why you are putting a logical value into
*A. It will make more sense if you use binaryorinstead of logical.Lets do that:
We have a new entry in our precedence table
Only change will occur in step 3 when a bitwise OR will be performed.
Lets have an example
lets say
elem = 3.A is pointing to the array
{1,2,3,3,4}1) ‘*A’s will be performed. It will just calculate the “Offsets” needed to do
loadorstoreinstructions of the processor.2)we will get a constant bit pattern :
1 << 3 = 10003)now for
|we needrvaluesas both operands. So now aloadinstruction will be performed to fetch the value stored in the memory. Say its2. So we will get0010 | 1000 = 10104)A store instruction will be performed to put this bit pattern into the memory so the array will look like
{1,A,3,3,4}Explanation for too much verbosity: I think this can help if future users who will try to find how to dissect a complicated expression by language rules.