468,532 Members | 1,647 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

int Property Problem - very odd indeed


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
Nov 17 '05 #1
11 1164
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?

Nov 17 '05 #2
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...

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

Nov 17 '05 #3


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:

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
Nov 17 '05 #4
On Wed, 2 Nov 2005 09:20:26 +0100, "Robert Heuvel" <ro***********@isopass.com> wrote:
I don't see you using properties (properties have getters/setters), what you are listing are fields!
Thanks for setting me straight on this.

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".
Thanks for the response, Robert.

I do know to use different names for accessors and fields
- I'm not THAT stoopid.

This problem is happening in the middle of a method
- and nothing is being passed as parameters as the fields involved
are members of the same class as the methods that are using them
(and they are all private methods and fields on top of that).

I'm still trying stuff - and I'll post back later with what happens
next in this dark tale of woe ...
################################################## #########################
"wASP" <wylbur[at]ev1[dot]net> schrieb im Newsbeitrag news:8n********************************@4ax.com...

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
Nov 17 '05 #5
On 2 Nov 2005 00:20:52 -0800, "Bruce Wood" <br*******@canada.com> wrote:
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?


This is something that I've been trying, but the problem
hasn't manifested itself in the toy as of yet.

- wASP
Nov 17 '05 #6

"wASP" <wylbur[at]ev1[dot]net> wrote in message news:ha********************************@4ax.com...
On 2 Nov 2005 00:20:52 -0800, "Bruce Wood" <br*******@canada.com> wrote:
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?


This is something that I've been trying, but the problem
hasn't manifested itself in the toy as of yet.


Try starting from the Problem version and cutting things out of it.
After each culling you test it to see if the problem remains.
If so...keep going until it is barebones
If not, look very closely at the stuff you just removed.

And take a good look everywhere your _ndx variables are modified

Good luck
Bill
Nov 17 '05 #7

UPDATE ... AND RESOLUTION ...

OK - so I tried moving the indexing fields into another class,
then made it the base class to the class that the fields
were members of, set access to private for both integer fields,
then created GET and SET accessors to control access to the fields.

It didn't work.

The value for que_ndx was STILL being altered
whenever the value for stk_ndx was incremented.

The common denominator in this is that both of the indexing fields
are referenced in a member accessor for the main (derived) class.
I mentioned before that, whenever I commented out a conditional IF
statement that makes use of the que_ndx field, that there was
a change in behavior.

I THEN proceeded to alter those accessors (there were two
that used the fields) - turning them into methods - member functions.
IT WORKED!
HEY MICROSOFT: YOU HAVE A PROBLEM WITH ACCESSORS IN C#!
Moral of the story: Whenever you've got some weird shit
like that happening, suspect any accessors that you might
be using in the class. I know that this garbage caused me
a lot of grief - not to mention lost time.

I want to thank everyone who responded - your input is appreciated.

Later gang!

wASP
################################################

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

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
Nov 17 '05 #8

"wASP" <wylbur[at]ev1[dot]net> wrote in message news:0g********************************@4ax.com...
<snip>
I THEN proceeded to alter those accessors (there were two
that used the fields) - turning them into methods - member functions.
IT WORKED!
HEY MICROSOFT: YOU HAVE A PROBLEM WITH ACCESSORS IN C#!


I am not prepared to blame Microsoft just yet.
You have yet to post a simple program that demonstrates the problem.
I have NEVER had problems using properties.

Now that you THINK you have isolated the cause of the problem, why don't you post a sample so that
we can verify the problem for ourselves.

Perhaps it is Microsoft's issue, and perhaps it isn't.

Bill
Nov 17 '05 #9
I side with Bill.

Please post the broken code so that we can all test it. If it is a bug
in the Framework, which is extremely unlikely but possible, then we
would all benefit from having it isolated and fixed. Simply saying,
"Hey Microsoft, you have a problem with accessors in C#" without
posting any offending code or nailing down exactly what that problem is
will not get any action from Redmond, nor should it.

Nov 17 '05 #10
On Fri, 04 Nov 2005 15:50:52 GMT, "Bill Butler" <qw****@asdf.com> wrote:

"wASP" <wylbur[at]ev1[dot]net> wrote in message news:0g********************************@4ax.com...
<snip>
I THEN proceeded to alter those accessors (there were two
that used the fields) - turning them into methods - member functions.
IT WORKED!
HEY MICROSOFT: YOU HAVE A PROBLEM WITH ACCESSORS IN C#!
I am not prepared to blame Microsoft just yet.
You have yet to post a simple program that demonstrates the problem.
I have NEVER had problems using properties.

Now that you THINK you have isolated the cause of the problem, why don't you post a sample so that
we can verify the problem for ourselves.

Perhaps it is Microsoft's issue, and perhaps it isn't.

Bill


---------------------------------------------

On 4 Nov 2005 09:24:38 -0800, "Bruce Wood" <br*******@canada.com> wrote:
I side with Bill.

Please post the broken code so that we can all test it. If it is a bug
in the Framework, which is extremely unlikely but possible, then we
would all benefit from having it isolated and fixed. Simply saying,
"Hey Microsoft, you have a problem with accessors in C#" without
posting any offending code or nailing down exactly what that problem is
will not get any action from Redmond, nor should it.


Sorry guys - I can't replicate the problem with a toy,
and, for reasons of my own, I'm not going to post all of
the source code for my project - for one thing it's too big
- in the thousands of lines.

If there's anyone in the
Houston/Katy/Sealy/Brenham/Conroe/Bryan/Tomball (Texas) area
that is interested, then I might arrange to pay them a visit
- bringing my source code
- and load it on their system for a demonstration
- wiping it off afterwards.

Yes: It's apparent to me that this is Microsoft's problem.

How else can you explain my problem just disappearing
like it did after converting accessors to methods
(and changing nothing else)?

... ESPECIALLY in light of the fact that the problem
manifested itself in such a strange way in the first place?

I didn't really expect Redmond to take any action on this
based upon my posts, but just to make note of it
- to make everyone aware of it.

At least I can give the rest of you a "heads up" on this issue.
If any of you ever encounter a situation like mine again
- where something strange like this is happening
- then you have a suspect to consider.
Consider yourselves warned: Watch out for accessors!
- wASP
Nov 17 '05 #11

"wASP" <wylbur[at]ev1[dot]net> wrote in message news:bl********************************@4ax.com...
On Fri, 04 Nov 2005 15:50:52 GMT, "Bill Butler" <qw****@asdf.com> wrote: <snip> Sorry guys - I can't replicate the problem with a toy,
and, for reasons of my own, I'm not going to post all of
the source code for my project - for one thing it's too big
- in the thousands of lines.
So post the get accesor, the new method, and the calling code here for us to have a look-see
Yes: It's apparent to me that this is Microsoft's problem.

How else can you explain my problem just disappearing
like it did after converting accessors to methods
(and changing nothing else)?


You obviously needed to change the code that used the Property(get accesor) as well
A get Accessor is nothing more than a method under the covers.
Look, back in your original post you wrote
--------------------------------------
Again, it's pretty straight-forward:
stk_ndx += 1;

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

--------------------------------------

This is VERY easy to Prove....ready
replace
stk_ndx += 1;
with
Console.WriteLine("Before[stk_ndx:{0} que_ndx:{1}]", stk_ndx, que_ndx);
stk_ndx += 1;
Console.WriteLine(" After[stk_ndx:{0} que_ndx:{1}]", stk_ndx, que_ndx);

If what you say is true, both will be incremented in the 2nd WriteLine.
I am willing to bet that this is NOT what is happening.
You may be happy walking away from this KNOWING Microsoft was to blame.
I on the otherhand have SERIOUS doubts about YOUR code.

Problems the "Just go away" for no good reason, have an annoying habit of coming back at a much
worse time. You may think you worked around a Microsoft bug, but the odds are that you have a
gremlin lurking in your code.

Good luck
Bill




Nov 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jonjon | last post: by
2 posts views Thread by Lee Crowe | last post: by
43 posts views Thread by Steven T. Hatton | last post: by
18 posts views Thread by Robin Becker | last post: by
13 posts views Thread by Peter Kirk | last post: by
reply views Thread by Stephen Carson | last post: by
4 posts views Thread by patrick j | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.