Objective C: How does 7 - 1 = 3?
NSLog(@"Before: %d",currentArticle);
currentArticle--;
NSLog(@"SUBTRACT %d",currentArticle);
"currentArticle" is an integer. This is only being echoed once in my console. If I do not run this subtraction, the number "currentArticle" remains at 7.
This is being run in the main thread, and only run once per user interaction.
I have also tried
currentArticle = currentArticle - 1;
With the same result. Am I taking crazy pills?
Thanks!
Edit:
Declared as follows:
extern int *currentArticle;
And assigned later as:
currentArticle = 0;
I tried rewriting as this:
int *curArticle; // in my .h file
curArticle = 1;
And then I run the
curArticle--;
and it still开发者_开发知识库 decrements by two...
I have stepped through the code and ensured there are no other calls hitting this variable.. Thanks for the feedback so far, I will keep hacking away at it.
I concur with the comments above. I'd bet a dollar that your code looks like:
int *currentArticle = 7; // or something
currentArticle may not even be a pointer to an int, specifically, but it's very likely a pointer to some 4-byte type. The '--' and '++' operators, when applied to pointers, decrement or increment by the size of the type that's pointed to.
Things I think of: Threads (if it's a strange problem, there are threads)? Or is it called by an event (which is triggered more than once)?
精彩评论