3 Replies - 293 Views - Last Post: 11 January 2013 - 11:53 AM Rate Topic: -----

#1 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 1,002
  • Joined: 30-July 08

Question about variables (vague question desc)

Posted 11 January 2013 - 11:05 AM

I know the topic is really vague, but I don't know how to formulate it!
It might not be isolated to C/C++ either but since I dev in C++ I put it here when I didn't know where else to put it!

Anyway here is my question.

Is it possible for a variable to change value if a program is running for whatever reason?
My friend say "no" I say "It is might not happen but it is possible".

This is the snippet of code he commented on
assert(s2 == s5);
	assert(s2 != s3);
	assert(s2 != s5); 


My argument is that something in the computer might unintentionally or by corruption change the value in the memory(?)location my "s2" is "assigned" to, so if the first assert passes and the program continues to the next and that passes too it MIGHT happen that the next assert also passes because by some "fluke" something in the computer changed the value so it will pass. My friend say it is impossible, for me is is possible even if it is a very small possibility for it to actually happen.

So even if it is really unlikely can it happen?
I hope I was clear enough in what I wanted to know! :)/>/>

This post has been edited by FrozenSnake: 11 January 2013 - 11:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Question about variables (vague question desc)

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3099
  • View blog
  • Posts: 10,887
  • Joined: 08-August 08

Re: Question about variables (vague question desc)

Posted 11 January 2013 - 11:33 AM

I'd say it's possible. For example, if you overwrite the end of an array, all bets are off! It can change anything, which is why its behavior is undefined.
Was This Post Helpful? 1
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1363
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Question about variables (vague question desc)

Posted 11 January 2013 - 11:37 AM

Yeah I would say its definitely possible, but extremely unlikely unless you enjoy messing around with memory and have no idea what you are doing.

Or are we talking about some kind of hardware malfunction that could change the value?

This post has been edited by Ryano121: 11 January 2013 - 11:39 AM

Was This Post Helpful? 1
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1431
  • View blog
  • Posts: 4,966
  • Joined: 19-February 09

Re: Question about variables (vague question desc)

Posted 11 January 2013 - 11:53 AM

Although the argument seems to be about the definition of impossible, I remember reading about transients (electronics) a while ago. Possible causes for faults could be anything from cosmic rays to static discharges or surges.

Memory tester : Detected faults


Causes and Effects of Transient Voltages

This post has been edited by #define: 11 January 2013 - 11:56 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1