objective c - Creating and assigning a value to lvalue when the rvalue depends on the lvalue -
i bit surprised see code not throw compile error, , bit curious why works.
packet
object contains byte-array, , read these custom methods. function read bytes location
length
.
usually, write:
uint8_t byte; byte = *(uint8_t*) [packet getbytes:&byte startingfrom:&bytelocation length:sizeof(byte)];
but surprise see following line seems valid.
uint8_t byte = *(uint8_t*) [packet getbytes:&byte startingfrom:&bytelocation length:sizeof(byte)];
can illuminate me how right hand side of statement can depend on left hand side have been created? there potential pitfalls should worried though not getting compile time errors (for ios 8 application)? thanks
edit:
without getting specifics of why function written way (which reducing lines of code on page), function copy value byte
array of bytes, , returns value. auto advances bytelocation length parameter, can call these lines 1 after parse byte data array it's value components.
the packet object contains method:
- (nonnull void*)getbytes:(nonnull void*)buffer startingfrom:(nonnull nsuinteger*)location length:(nsuinteger)length { nsrange range = nsmakerange(*location, length); [self.data getbytes:buffer range:range]; // self.data nsdata* *location = range.location+range.length; return buffer; }
that return value convenience trigger kvo notifications when used in other cases, not particular case.
also, yes while example using objective-c describe question, write these functions in c / c++, why tagged c/c++ , see similar behavior. figured understands more how these statements broken down assembly level might enlighten me. stated in comments, suspect lvalue here getting created first, rvalue evaluated, , rvalue assigned lvalue storage area, know if theory correct or there explanation.
Comments
Post a Comment