473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1349
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jonjon | last post by:
Hi, Is there any way of adding a property to an HTML element ? I heard about the "prototype" method but it doesn't work for HTML elements such as Images, or Paragraphs... Netscape implements...
2
by: Lee Crowe | last post by:
Hi I am in the middle of creating a control and wondered if someone could help me with a problem I have. My control is based on an existing control but I have added at least twenty properties...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
18
by: Robin Becker | last post by:
Is there a way to override a data property in the instance? Do I need to create another class with the property changed? -- Robin Becker
13
by: Peter Kirk | last post by:
Hi there, can someone tell me what exactly a "property" is in a C# class? As far as I can see it is "two methods" - ie a getter and a setter for an instance variable. What is the difference...
0
by: Stephen Carson | last post by:
I cannot see a browsable property I have added in the Properties Window. Using C++ in Visual Studio .NET 2003 I have added a property to my managed class: public:
15
by: Lauren Wilson | last post by:
Owning your ideas: An essential tool for freedom By Daniel Son Thinking about going into business? Have an idea that you think will change the world? What if you were told that there was no way...
2
by: | last post by:
I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control. In other words, let's say I have the following: MyPage.aspx ....with the following...
4
by: patrick j | last post by:
Hi First I must apologise to Mr. Dorayme for my use of his web-page as the example for my question. In order assist in making him feel better I'll mention it is an excellent article. However...
2
by: cjard | last post by:
I ask, because I have a textbox bound to a bindingsource, which is bound to a datatable(row) The datatable is typed, and hence exports a Property called Column1 I added another property to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.