p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Ivor Horton's Beginning Visual C++ 2005 (http://p2p.wrox.com/forumdisplay.php?f=249)
-   -   ERRATA TOPIC (http://p2p.wrox.com/showthread.php?t=42802)

tpangborn May 20th, 2006 12:53 AM

ERRATA TOPIC
 
Errata: "Beginning Visual C++ 2005" p. 175
The outupt of Ex4_05.cpp is shown near the bottom. The addresses of &number1 and pnumber are shown to be 0012FEC8 and 0012FEBC, respectively. If one calculates the difference between the two addresses (C8-BC), the difference = 0x0000000C or 12(dec). As pointed out on p. 176 just below the midpoint of paragraph 6, the difference between &number1 and pnumber should be 4 bytes since they occupy adjacent memory locations for each [u]type long</u> variable. The last sentence of paragraph 6, p. 176, "The output demonstrates that everything is working as you would expect", is not true for the output of Ex4_05.cpp as written on p. 175. The good news is that the compliled and executed code on my computer showed the correct 4-byte spread between the addresses of &number1 and pnumber.

SilverFoxtor

Nick Y May 24th, 2006 01:18 PM

I have a similar problem but, unlike you, my addresses are 0012FF54 and 0012FF48 giving a difference of dec 12 when I compile and run the code. (This is with Visual Studio 2005 (version 8.0.50727.42.)

I even tried taking the example code and running it with Visual Studio, in case I had made a typing error.

Interestingly, if I run the same code through my Borland compiler, I get a difference of 4 bytes.

Is this a compiler error in Visual Studio?

Nick

tpangborn May 25th, 2006 12:03 AM

Nick,

I must admit that I did not use Visual Studio to complile the code for the Errata that I posted. I used the DevC++ compliler for this one and I got the correct 4-byte interval. Maybe someone with some expertise could explain why Visual Studio has a 12-byte interval.

SilverFoxtor

Nick Y May 25th, 2006 03:28 PM

I went to the forums at msdn.microsoft.com/vstudio/support/forums/ and posted the question in Visual C++ General. V helpful people there came back with solution. Quoting vbvan:

'Because the flag "basic runtimes check"(/RTC1) is on by default.

When this flag is on, the complier will add some extra variables for check purpose.'

Reseting the flag produces 4 bytes intervals.


tpangborn May 26th, 2006 01:53 PM

Thanks for that research, Nick! One can see how the entry in the book is still misleading since it does not give this information or elude to Visual Studio giving an interval greater than 4 bytes for whatever reason. The author should not have refered to this 4-byte interval or adjacent memory locations at all, even though it is true with optimized code.

SilverFoxtor


All times are GMT -4. The time now is 03:52 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.