|
-
March 22nd, 2013, 06:42 AM
#11
Re: Pseudopointers
 Originally Posted by eightyfive
As I told before, we're talking from different perspectives, and I just shown you that my code REALLY WORKS
There is a difference between a "single observed behaviour" and a "rule" or "a proof".
Now lets say I have a 6 sided die. I roll it and it comes up as 5.
I hereby declare and prove that when you roll a six sided die, it will always return a 5 and nothing else because that's the single behaviour I observed. It just doesn't work like that.
You wrote a piece of code.
You ran it and it had the behaviour you expected. great for you.
But that doesn't make it valid C++ or guaranteed to work in every situation on every compiler on every platform. What you are doing simply is not guaranteed by the C++ spec.
I can write a whole bunch of C++ code that will produce different results that will depend on what compiler and compiler options it's being compiled with. If you use invalid c++ constructs, you'll get unpredictable results.
Your code may very well stop working when you install a new version of the compiler. Or if you use different compiler settings.
as to the "why would a compiler do this?" question you asked. Simple. because the compiler may have some obscure reason to organize memory in the way it does. all you do is tell the compiler to create 10 variables, there is no absolute relation between them and the compiler is free to put them anywhere he wants. Under the right optimisation settings, there may be very good reasons to not have them all consecutive in memory.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|