Hi, I'm looking at this code, and I have a quesiton about this statement:
const SomeClass & crSomeThing = (bIsValid) ? SomeClassObjA : SomeClassObjB; Assignment requires an lvalue, no? Where is the lvalue? I see the modifier (const), the type (SomeClass), and then I expect to see a variable name but instead I see an address-of operator (&). How is "&crSomeThing" a valid variable name in this variable declaration statement? Thanks, Will ----- Original Message ---- From: Thomas Hruska <[EMAIL PROTECTED]> To: c-prog@yahoogroups.com Sent: Friday, August 31, 2007 8:28:32 AM Subject: Re: [c-prog] MSVC Compiler optimized away variable = Confusion while Debugging? Ananth wrote: > This was pretty interesting. > I was debugging a Release version with Optimization enabled in Visual > Studio. > This is the simplified code: > > bool IsValid() > { > bool bReturnValue = false; > > if ( /*Some Check*/ ) > bReturnValue = true; > > return bReturnValue; > } > > void foo() > { > . > . > . > bool bIsValid = IsValid(); > const SomeClass & crSomeThing = (bIsValid) ? SomeClassObjA : > SomeClassObjB; > //Mis-leading: bIsValid is always false, even when IsValid() returns > true. > //bIsValid is false, but "crSomething" refers to "SomeClassObjA" > . > . > } > > > It took me some time to figure out it can only be because MSVC Compiler has > optimized away "bIsValid" variable. > So debugger shows bIsValid as false even though function returned true. > > It could be confusing and a mystery to innocent (forgetting one would have > debugged in Debug mode first) > > Any thoughts? Please share. > > Thanks > - Ananth Using the debugger in Release mode is not always accurate. It jumps around a lot because of compiler optimizations. Additionally, variable values are also not always accurate as you have discovered. That's the whole point of Debug mode: You want to debug the application, so the compiler doesn't optimize anything. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleS oft.com/MyTaskFo cus/ ____________________________________________________________________________________ Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 [Non-text portions of this message have been removed]