int属性问题 - 确实非常奇怪 [英] int Property Problem - very odd indeed

查看:62
本文介绍了int属性问题 - 确实非常奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我在课堂上有一对int属性。


有问题的属性是索引值

- 但这与我的问题无关

- 或者它只是对症......有点像。


它们声明如下:


公共类obj_set_class

{

private int que_ndx;

private int stk_ndx;

..

..

..

}


这是非常简单的 - 没有什么不寻常的。


现在问题......


我正在追逐一个bug,而且,当我踩到

时,使用其中一个int属性的方法(stk_ndx),

我执行一个语句,增加那个int属性,

和OTHER int属性(que_ndx)也增加。


再次,它很直接:

stk_ndx + = 1;

执行此语句后,que_ndx增加,

以及stk_ndx。


我唯一猜测是两个int符号在给出相同的地址的情况下,这是一个奇怪的。


有没有人知道造成这种情况的原因是什么?

...以及如何修复它?

感谢!


- wASP


Hi,

I''ve got a pair of int properties in a class.

The properties in question are indexing values
- but that''s not relevant to my problem
- or it''s just symptomatic ... sort of.

They are declared as follows:

public class obj_set_class
{
private int que_ndx;
private int stk_ndx;
..
..
..
}

It''s pretty straight-forward - nothing out of the ordinary.

NOW for the problem ...

I was chasing after a bug, and, while I was stepping through
the method that uses one of those int properties (stk_ndx),
I execute a statement that increments that int property,
and the OTHER int property (que_ndx) gets incremented as well.

Again, it''s pretty straight-forward:
stk_ndx += 1;

After this statement is executed, que_ndx gets incremented,
as well as stk_ndx.

My only speculation is that both int symbols are being
given the same address - which would be bizarre.

Has anyone got any idea as to what is causing this?
... and how to fix it?
THANKS!

- wASP

推荐答案

这里没有足够的信息来形成关于什么'

'的理论。


你能不能减肥这个类有几十行代码

,在编译和运行时,演示了这个问题?然后发布

结果类?

There''s not enough information here to form a theory as to what''s going
on.

Can you whittle the class down to a couple of dozen lines of code
which, when compiled and run, demonstrate the problem? Then post the
resulting class?


我没有看到你使用属性(属性有getter / setter),你列出的是字段!

如果你要使用属性,我很确定问题会由于编译器强迫你清理你的代码而自行消失。

唯一的方法(除了调用不安全的代码)你可以搞砸就像你描述的那样,将que_ndx和stk_ndx作为ref params传递给方法。由于它们被声明为私有,因此您必须将它们分发。来自obj_set_class或该类的方法本身就是罪魁祸首。


public class obj_set_class {

private int mque_ndx; //更改名称非常重要

private int mstk_ndx; //更改名称非常重要


public int que_ndx {//" property"

get {return mque_ndx;} //" getter"

set {mque_ndx = value;} //" setter"

}

public int stk_ndx {

get {return mstk_ndx;}

set {mstk_ndx = value;}

}

}


如果您更改上面的类并更改字段的名称(非常重要),您的类/程序的其余部分将使用属性而不是字段(正是您想要发生的事情!)。属性不能用作参考参数,所以我要解决你的问题将离开。


wASP < wylbur [在] EV1 [点]净> schrieb im Newsbeitrag新闻:8n ******************************** @ 4ax.com ...
I don''t see you using properties (properties have getters/setters), what you are listing are fields!
If you would use properties instead I''m quite sure the problem would go away by itself due to the compiler forcing you to clean up your code.
The only way (besides calling unsafe code) you can "screw up" like you described is by passing que_ndx and stk_ndx as ref params to a method. Since they are declared as private you must be either "handing them out" from obj_set_class or a method of that class itself is the culprit.

public class obj_set_class {
private int mque_ndx; // it is VERY IMPORTANT to CHANGE the name
private int mstk_ndx; // it is VERY IMPORTANT to CHANGE the name

public int que_ndx { // "property"
get {return mque_ndx;} // "getter"
set {mque_ndx = value;} // "setter"
}
public int stk_ndx {
get {return mstk_ndx;}
set {mstk_ndx = value;}
}
}

If you change your class like above AND CHANGE the names of your fields (VERY IMPORTANT) the rest of your class/programm will use the properties instead of the fields (exactly what you want to happen!). Properties CANNOT be used as ref params, so I''m definte your problem will "go away".

"wASP" <wylbur[at]ev1[dot]net> schrieb im Newsbeitrag news:8n********************************@4ax.com...



我在课堂上有一对int属性。

有问题的属性是索引值
- 但这与我的问题无关
- 或者它只是有症状......有点。

它们声明如下:
public class obj_set_class
{private int que_ndx;
private int stk_ndx;



}
<这是非常直截了当的 - 没有什么与众不同的。

现在问题......

我正在追逐一个bug,并且,当我踩着使用其中一个int属性(stk_ndx)的方法时,
我执行一个增加int属性的语句,
和OTHER int属性(que_ndx)增加同样。

再次,它非常简单:
stk_ndx + = 1;

A执行此语句后,que_ndx会增加,
以及stk_ndx。

我唯一的猜测是两个int符号都被赋予相同的地址 - 这将是奇怪的。

有没有人知道是什么导致这个?
......以及如何解决它?


感谢!

- wASP

Hi,

I''ve got a pair of int properties in a class.

The properties in question are indexing values
- but that''s not relevant to my problem
- or it''s just symptomatic ... sort of.

They are declared as follows:

public class obj_set_class
{
private int que_ndx;
private int stk_ndx;
.
.
.
}

It''s pretty straight-forward - nothing out of the ordinary.

NOW for the problem ...

I was chasing after a bug, and, while I was stepping through
the method that uses one of those int properties (stk_ndx),
I execute a statement that increments that int property,
and the OTHER int property (que_ndx) gets incremented as well.

Again, it''s pretty straight-forward:
stk_ndx += 1;

After this statement is executed, que_ndx gets incremented,
as well as stk_ndx.

My only speculation is that both int symbols are being
given the same address - which would be bizarre.

Has anyone got any idea as to what is causing this?
... and how to fix it?


THANKS!

- wASP






更新......

好​​的 - 我昨天有一些不相关的东西出现了

打断了我,把我的注意力转移到了这个问题上,

我没有很多时间专注于它。我还在尝试一些东西,

,我打算用

跟进我的后续帖子,这是我用过的所有尝试得到的结果。


这个过程仍在进行中 - 我还没有用尽我所有的b $ b替代品。我做了最初的帖子 - 开始这个帖子

- 希望有人可能有类似的经历

到我正在拥有的那个 - 或者遇到过这个问题

之前和别人在一起 - 并且可以给我一个甜蜜而简单的b $ b解释 - 以及一个可行的解决方案。我想我是希望对那个人抱有希望 - 但是要求它并没有什么坏处。

首先,我要感谢所有回复的人

- 一如既往,感谢您的投入。

我要感谢那些根据我的术语纠正我的人:

我的意思是整数* FIELDS * - 不是属性

- 而且我是一个大胖子,胖子,stopoo-head for the gaffe

- 我脸红了尴尬。 < cringe>

随着我花在这上面的时间,我已经尝试了各种各样的东西......以及各种奇怪的东西...... br />
一直在发生。


其中一个,我尝试在课堂上创建一个新的FIELD

- 称之为que2_ndx

- 将旧版本留在原位(que_ndx)

- 只需为其分配值0

- 并且发生同样奇怪的事情到新的现场

- 到que2_ndx

- 并且旧的FIELD(que_ndx)不受影响。


一个共同点是这个特定的索引字段

(que2_ndx)用于GET访问器 - 尽管该访问器

不用于问题显现的方法中。 />

我改变了GET访问器 - 试图评论出一个

条件IF引用索引字段

(起初是叫做que_ndx但现在称为que2_ndx)

- 比较两者值的IF语句:


// if(que2_ndx< stk_ndx)

que2_ndx ++;


......事情变得更奇怪:

编译后 - 用条件IF评论out

- 而不是索引字段que2_ndx递增

执行指令以增加语句应该递增的索引变量

(stk_ndx)

- 现在,在执行系统函数调用的
后,que2_ndx字段会增加一个对象添加到数组列表中

- 位于增加指令之前的位置

stk_ndx。


我开始认为存在某种故障<访问器机制中的
,我正在考虑重写访问器的替代方案

- 将它们变成方法

- 并取消使用在我有这个问题的

类中完全存取访问者。


还有一些m然而,在此之前,我要尝试的东西是




我没有在任何一个中使用视觉工作室,

所以它不是因素。


我尝试在另一个盒子上安装ASP.NET和IIS,

运行这个生物其他系统,

和我有相同的行为

- 所以这个问题对我的特定系统来说并不是唯一的。


我会稍后回复我的结果。


再次感谢!


########## ############################################

星期二,2005年11月1日23:33:27 -0600,wASP< wylbur [at] ev1 [dot] net>写道:


UPDATE ...

OK - I had some unrelated stuff come up yesterday that
interrupted me and diverted my attention away from this problem,
and I didn''t have much time to focus on it. I''m still trying stuff,
and my intention was to make a follow-up post with
the results that I got with everything that I''ve tried.

That process is still on-going - I''ve not yet exhausted all of my
alternatives. I made the initial post - starting this thread
- in the hopes that someone might have had a similar experience
to the one that I''m having - or have encountered this problem
before with someone else - and could give me a sweet and simple
explanation - along with a viable solution. I guess I was
hoping against hope on that one - but it doesn''t hurt to ask.
First of all, I want to thank all of those who responded
- as always, I appreciate your input.
I want to thank those of you who corrected me on my terminology:
I meant integer *FIELDS* - not properties
- and I''m a big, fat, stoopid, poopoo-head for that gaffe
- I''m red-faced with embarrassment. <cringe>
With the time that I''ve spent on this, I''ve tried all kinds
of different stuff - and all kinds of strange things
have been happening.

For one, I tried creating a new FIELD in the class
- calling it que2_ndx
- leaving the old one in its place (que_ndx)
- and just assigning to it a value of 0
- and the same weird stuff is happening to the new FIELD
- to que2_ndx
- and the old FIELD (que_ndx) is untouched.

The one common denominator is that this particular indexing field
(que2_ndx) is used in a GET accessor - though that accessor
is not used in the method where the problem is manifesting itself.

I altered that GET accessor - tried commenting out a
conditional IF that makes reference to the indexing field
(which at first was called que_ndx but is now called que2_ndx)
- an IF statement that compares the values of the two:

// if (que2_ndx < stk_ndx)
que2_ndx++;

... and things got even MORE bizarre:
After compiling - with the conditional IF commented out
- instead of the indexing field que2_ndx being incremented
afer the execution of the instruction to increment the
indexing variable that the statement SHOULD increment (stk_ndx)
- the que2_ndx field now gets incremented after the execution
of a system function call that adds an object to an array list
- which is positioned BEFORE the instruction that increments
the stk_ndx.

I''m beginning to think that there''s some kind of a glitch
in the accessor mechanism, and I''m considering the alternative
of rewriting the accessors - turning them into methods
- and eliminating the use of accessors altogether in the
class where I''m having this problem.

There is still some more stuff that I''m going to try
before this, however.

I''m not using visual studio in any of this,
so it isn''t a factor.

I tried installing ASP.NET and IIS on another box,
ran this critter on that other system,
and I got the same behavior
- so this problem isn''t unique to my particular system.

I''ll post back later with my results.

THANKS AGAIN!

################################################## ####
On Tue, 01 Nov 2005 23:33:27 -0600, wASP <wylbur[at]ev1[dot]net> wrote:



我在课堂上有一对int属性。

有问题的属性是索引值
- 但这与我的问题无关
- 或者它只是对症......有点像。

他们是声明如下:

public class obj_set_class
{private int que_ndx;
private int stk_ndx;



}
这很直截了当 - 没有什么不同寻常的。

现在问题......
和OTHER int属性(que_ndx)也会增加。

再次,它非常简单:
stk_ndx + = 1;

执行此语句后,que_ndx会增加,
以及stk_ndx。

我唯一的猜测是两个int符号都被赋予相同的地址 - 这将是奇怪的。

有没有人知道是什么导致了这个? /> ...以及如何修复它?

感谢!

- wASP

Hi,

I''ve got a pair of int properties in a class.

The properties in question are indexing values
- but that''s not relevant to my problem
- or it''s just symptomatic ... sort of.

They are declared as follows:

public class obj_set_class
{
private int que_ndx;
private int stk_ndx;
.
.
.
}

It''s pretty straight-forward - nothing out of the ordinary.

NOW for the problem ...

I was chasing after a bug, and, while I was stepping through
the method that uses one of those int properties (stk_ndx),
I execute a statement that increments that int property,
and the OTHER int property (que_ndx) gets incremented as well.

Again, it''s pretty straight-forward:
stk_ndx += 1;

After this statement is executed, que_ndx gets incremented,
as well as stk_ndx.

My only speculation is that both int symbols are being
given the same address - which would be bizarre.

Has anyone got any idea as to what is causing this?
... and how to fix it?
THANKS!

- wASP




- wASP



- wASP


这篇关于int属性问题 - 确实非常奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆