In XCode 4.2, I find that I can write a statement like this:
[obj = obj method];
And there is no error or warning about this.
So, I want to know how the compiler will interpret this? Is this the same as:
obj = [obj method];
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.
Turn up your warning levels. Clang will emit a warning (
-Wself-assign):It is not the same as
obj = [obj method];. It is interpreted as:and the compiler can just omit the self-assign. That is, this program prints
a:…but why would you write a program using this exact statement? It will be confusing to interpret or just awkward, for many people.