In linux make file:
I want to run the output program only in case of successful compilation.
Is there a way to do this?
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.
Like others have said, use
&&. For example:There are two things that make this work; firstly there is a convention in UNIX that all things that succeed return 0 (including C programs). There’s an old joke that helps you remember this “the Roman Empire fell because the Romans didn’t have a zero with which to successfully terminate their C programs”.
Secondly,
&&is a “short-circuit” version of Boolean “and”. That is, it will evaluate the expression on its left hand side and ONLY if that is0will it evaluate the expression on the right hand side. This is also the difference between the Java operators&&(short circuit) and&(always evaluates both operands). Many imperative languages contain both sorts of operators, in case there are side effects (e.g. I/O, variable updates) in the right hand operand of the Boolean expression, in which case you definitely want to evaluate both operands. Some people, however, would say that it’s bad style to embed side effects in this manner.