Re: My local variable addresses are changing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Carl Daniel [VC++ MVP] (cpdaniel_remove_this_and_nospam_at_mvps.org.nospam)
Date: 03/23/04


Date: Tue, 23 Mar 2004 13:15:37 -0800

Sounds like they're calling a function that messed with the stack pointer.
Look for use of alloca or longjmp, to name a couple of suspects.

-cd

Rudy Ray Moore wrote:
> I work on a large native c++ application. We have about 15
> developers. We recently moved to "Visual C++ .net 2003 7.1." Two
> devleopers have seen an odd problem since we migrated.
>
> The address of local variables change when they are passed to another
> function by reference (or when their addresses are passed). The
> address of the variable increases by 420 bytes.
>
> An example below illustrates the problem (but the problem does not
> happen in this example). While the problem is quite reproducable
> when it appears, I cannot make it appear at will.
>
> Looking at assembly doesn't help because in assembly local variables
> are listed by their c++ variable name in square brackets (assembly
> doesn't show the actual adresses of local variables). The assembly
> thing is also pretty hard to use (scroll bar don't work...?).
>
> The problem just appears in a certain "group" of developers (math
> people, not programmers), so I might suspect they are doing something
> weird in their project files or coding.
>
> Does anyone have any clues about how I can solve this problem?
>
> Thank you!
>
> Rudy
>
> ===
>
> class A
> {
> void f(double& d){}
>
> void g()
> {
> double d;
>
> cout << &d; // "0x0012fac8"
>
> f(d);
>
> cout << &d; // "0x0012fe10" (== 0x0012fac8 + 420)
> }
> }
>
> void main()
> {
> A a;
> a.g();
> }



Relevant Pages

  • Re: fields for methods?
    ... than one method on a "Brush" object: ... void change_color; ... Sure, "encapsulation" is a buzzword with many competing definitions, ... the same as static local variables because static local variables are like ...
    (comp.programming)
  • Re: C99: Suggestions for style(9)
    ... at the start clearly points that there're no local variables used. ... non-scalar declarations in a function, then a compiler can coalesce them ... void f; ... struct Foo a; ...
    (freebsd-hackers)
  • Re: C99: Suggestions for style(9)
    ... There's no need to add more redundant parentheses. ... Last, but definitely not least, I added this paragraph about the use of local variables. ... Even considereing the extremly rare case of multiple non-scalar declarations in a function, then a compiler can coalesce them if their life ranges are disjoint. ... void f; ...
    (freebsd-hackers)
  • Re: fmemopen: assignment makes pointer from integer without a cast
    ... the restriction is not for the local variables. ... Identifiers beginning with 'str' followed by at least one lower case letter are reserved ... for use as identifiers with external linkage. ... void bar; ...
    (comp.lang.c)
  • Re: My local variable addresses are changing
    ... How could messing with the stack pointer change the address of a local ... > Rudy Ray Moore wrote: ... >> The address of local variables change when they are passed to another ...
    (microsoft.public.dotnet.languages.vc)