erreur: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ - logical-operators

I'm trying to compile dapl-myrinet-12-0.12 from sourceforge
I got
/root/dapl-myrinet-12-0.12/dapl/udapl/../common/dapl_ep_modify.c:584: erreur:
suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’
here is the "problematic" line :
if (ep_param->recv_evd_handle != NULL &&
(DAPL_BAD_HANDLE (ep_param->recv_evd_handle, DAPL_MAGIC_EVD) ||
! ((DAPL_EVD *)ep_param->recv_evd_handle)->evd_flags & DAT_EVD_DTO_FLAG))
any idea how to fix it ?

Like the error suggest, the code miss a couple of parenthesis around the last part of the condition (the corrected condition is exploded here to highlight matching parenthesis) :
if (
ep_param->recv_evd_handle != NULL &&
(
DAPL_BAD_HANDLE (ep_param->recv_evd_handle, DAPL_MAGIC_EVD) ||
!(
((DAPL_EVD *)ep_param->recv_evd_handle)->evd_flags & DAT_EVD_DTO_FLAG
)
)
)
You could also disable this check from GCC (if it's the compiler you use), with the -Wno-parentheses switch. Anyway, you should report this to the maintainer of the program to let hi fix his code.

Related

Writing an if statement when the value can be NULL or a string

I have a value that can be NULL or a string. The second test fails because a is of length 0.
How do I write an if-statement that handles both cases?
Example:
a <- NULL
if (is.null(a) | a=="something else then null") {
print("test")
}
is.null(a) || a=="something else then null"
(similarly, use && instead of & in a situation like this)
Explanation: when you use |, all conditions are checked one by one and then the "or" assertion is applied. This means that if one of the conditions is invalid, then there is an error, like in your case.
When you use ||, the "or" assertion is checked after each condition check. In your case, is.null(a) is TRUE. This means that is.null(a) "or" any other condition will also be TRUE, so there's no need to check the other condition.
This is based on my understanding of how it works, it's not a definition coming from the docs. I hope it's clearer.
More info: What's the differences between & and &&, | and || in R?

Having problems using && and/or || and reprogram the NthRoot function

So I am suppose to Use && and/or || and reprogram the NthRoot function. The NthRoot Function code is this:
NthRoot<-function(m,n) {
if(!is.integer(n)!=1) {
stop("Error: N must have length 1. Go away.")
}
else if (!is.integer(n) | is.numeric(n)) {
return(m^1/n)
}
else
stop('Error: You must input an interger or vector of intergers.
Existing...\n\n')}
When I replace if and else if, with double & and double |, I receive an error message, Error: unexpected '&&' in:
"NthRoot<-function(m,n) {
&&". I am having a hard time understanding this part of R programming so I'm struggling a lot. Any help is greatly appreciated. Thank you

Collection deny rule property undefined

When invoking this in the browser console:
Meteor.users.update({_id:'2MA7iPq7bNtfxGm6r'},{$unset:{'profile.taskInProgress':''}})
This Meteor server code is giving this error
TypeError: Cannot read property 'profile.taskInProgress' of undefined
Meteor.users.deny({
update: function (userId, doc, fields, modifier) {
const tasks = ['search', 'aSearch'];
return (!(
userId &&
userId == Meteor.userId() &&
(tasks.indexOf(modifier.$set['profile.taskInProgress']) >= 0) || //<--comment for next line to work
(modifier.$unset['profile.taskInProgress'] == '') // <-- or comment for the above line to work
));
}
});
it works if I comment out the "error line", but if I do that then I will loose the permission to $set it. So now it appears like I can have one or the other but not both permissions. Must be some problem with my code.
How to allow the client to unset the 'profile.taskInProgress' property?
i think you have a logic problem.
your expression is basically this:
!(a && b && c || d)
c is valid only when you're doing a $set, and d is valid only when you're doing an $unset.
if your expression were this (without the prefixing bang):
(a && b && c || d)
... then, for a $set, the evaluation will be: a, b, c. if those are all true, then the condition is satisfied. it does not need to proceed to evaluation of d. that's good, because i think that would fail due to lack of null check.
but if $unset is used, then i believe that c will fail, because of a lack of null check. (i'm not positive here, but i think that's what's going on).
but, you have the entire expression "notted". that's going to force evaulation of each of a, b, c, and d, regardless of whether $set or $unset is being used. and this will always fail due to lack of null checks.
what you really mean, i think, is:
!(a && b && (c || d))
as written, you could not have a userId, and as long as d is true (and null checks were in place), you would allow the operation.
to solve it, i would break out the evaulation from the overall logic. e.g.
let userIdExists = !!userId;
let requesterIsLoggedInUser = (userId === Meteor.userId());
let progressSet = (modifier.$set && (tasks.indexOf(modifier.$set['profile.taskInProgress']) >= 0));
let progressUnset = (modifier.$unset && (modifier.$unset['profile.taskInProgress'] == ''));
let allowed = userIdExists && requesterIsLoggedInUser && (progressSet || progressUnset);
let denied = !allowed;
return denied;
i tend to be verbose in logic situations like this, to ensure each condition is easily understood.
btw, why is this not expressed as an allow rule? returning "allow" instead of "!allowed" in a deny seems easier to read, imho.
edit: the allow version simply does a "return allowed;" at the end, instead of bothering with the denied variable.
if you're trying to debug, console.log() out all the vars to see if they're what you expect. if you want, update your question w/ those results and console logs of modifier so it's easier to confirm the logic for progressSet and progressUnset.

how will the precedence of && and != work in a logical statement?

While (ptr ! =NULL && dptr! = NULL && dptr->next! =NULL)
In this code if the pointer dptr is NULL will it work or will terminate?
If the statement is true or not is actually based not only on dptr but also on ptr and dptr->next. If the statement is true - the content if the while-loop will be executed.
The substatements (your camparisons to not NULL) are checked one after another - if one is false, the other will not be executed. This is true for most programming languages. Though I haven't checked with all.
Logical && as well as || have some inherent mechanism for fast return. They both go step by step from left to right substatement. (Plus () ). With && the check is aborted on the first false statement. With || the check is aborted on the first true statement. The other checks won't be reached.
So your statement will never check dptr->next != NULL for the case that dptr is actually NULL. So your statement is safe from access to NULL pointers.

error in switch function in R

to_select=cbind(te_matrix[i,j],te_matrix[j,k],te_matrix[i,k]);
te_ac=apply(abs(to_select),2,sort);
var_ac=apply(abs(to_select),2,order);
if(te_ac[1]<te_ac[2]-0.005){
switch(var_ac[1],
1= (del_arc<-rbind(del_arc,cbind(count-1,i,k)))
2= (del_arc<-rbind(del_arc,cbind(count-1,j,k)))
3= (del_arc<-rbind(del_arc,cbind(count-1,i,k))))
}
when I run this code, it throws error as followed:
M:/学习/毕业设计/传递熵R语言/triplenode.R:27:26: unexpected '='
26: switch(var_ac[1],
27: 1=
^
Did I make any mistake about the function "switch" in R
Yes. The switch function operates differently if the switching expression is numeric. Your switching expression is a number.
Since your switching expression is number, you don't need the = signs.
In either case, you also need commas separating the options
switch(var_ac[1],
del_arc<-rbind(del_arc,cbind(count-1,i,k)),
del_arc<-rbind(del_arc,cbind(count-1,j,k)),
del_arc<-rbind(del_arc,cbind(count-1,i,k))
)
The value of your var_ac[1] must evaluate (or be coerced) to the value 1,2, or 3, or the switch function will return NULL

Resources