I’m wondering if empty statements (i.e. null statements) evaluate to NOP or if it’s compiler dependent.
// Trivial example
int main()
{
;;
}
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.
It’s compiler dependent but the observable behaviour must be that nothing happens. In practice, I’m sure most compilers will emit no code at all for an empty expression.
And the observable behaviour is defined by:
This is really the only requirement for an implementation. It is often known as the "as-if" rule – the compiler can do whatever it likes as long as the observable behaviour is as expected.
For what it’s worth, these empty expressions are known as null statements:
If you really want a NOP, you can try:
This is, however, conditionally supported and its behaviour is implementation-defined.