This is a tale of copy and paste snafus. (Not sure if this is the right term, but it sounds fancy...)
I was making CRC checking in my FLAC player, and I was copying a minor part of the CRC-8 part to make the CRC-16 part. In the debugging I observed that all the generated values were in the range 0..255, but it was supposed to be 16 bit.
What I did was:
Implementation:
- (uint16_t)CRC16 {
return mCRC16;
}
Definition:
- (uint8_t)CRC16;
Notice the mismatching return values of the definition and implementation.
What I didn't notice was the compiler complaining with a WARNING (not an error) that:
So even though the method definition didn't match, the runtime was happy to use the "substitute" instead, providing me with wrong values.
...what kind of function declaration syntax is that though? o_O
Isn't that Objective-C?
Yes, it is Objective-C. I originally mentioned that, but my browser crashed in the middle of editing, so I had to rewrite and forgot to mention that again.
Lol, my little mistake taught me something new about Obj-C too I know those things are resolved at runtime, and that opens for a lot of weirds stuff, but I didn't know that the definition would override the implementation.
Edit: And it was hard to start with Objective C with a C/C++ background. If you don't come up with good names, things may look like this:
Yes, it is weird, and it still feels weird and unnatural even after 2-3 years of Obj-C-ing... And you are sending messages, not calling methods. That is a whole world of difference, since sending messages means that everything is determined at run time. Calling methods are determined at compile time.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more