问题描述
NSLog(@"Before: %d",currentArticle);
currentArticle--;
NSLog(@"SUBTRACT %d",currentArticle);
currentArticle是整数。这只是正在我的控制台回荡一次。如果我不运行这个减法,数字currentArticle保持在7。
"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.
我也试过
currentArticle = currentArticle - 1;
使用相同的结果。我是不是疯了服用药丸?
With the same result. Am I taking crazy pills?
谢谢!
编辑:
声明如下:
extern int *currentArticle;
和后来的分配:
currentArticle = 0;
我试着重写,因为这:
I tried rewriting as this:
int *curArticle; // in my .h file
curArticle = 1;
然后我运行
curArticle--;
和它仍然由两个递减...
and it still decrements by two...
我已经通过code加强并确保没有其他电话打这个变量..感谢您的反馈到目前为止,我会坚持下去劈砍而去。
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.
推荐答案
我同意上述意见。我敢打赌一块钱,你的code如下:
I concur with the comments above. I'd bet a dollar that your code looks like:
int *currentArticle = 7; // or something
currentArticle甚至不是一个指向一个int,具体,但它很可能指向一些4字节类型。在' - '和'+'经营者,当通过的指向的类型的大小应用于指针,递减或递增
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.
这篇关于目标C:如何7 - 1 = 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!