Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18905

Re: addresses of variables

From Lowell Gilbert <lgusenet@be-well.ilk.org>
Newsgroups comp.lang.c
Subject Re: addresses of variables
References <9524023.127.1332068169176.JavaMail.geo-discussion-forums@ynbq18> <4F65D575.10F1@mindspring.com> <25634479.146.1332070955396.JavaMail.geo-discussion-forums@vbbdy9> <44vcm0ve21.fsf@be-well.ilk.org> <jk7ru4$om5$1@dont-email.me>
Date 2012-03-20 11:52 -0400
Message-ID <44y5qv46e7.fsf@lowell-desk.lan> (permalink)

Show all headers | View raw


Stephen Sprunk <stephen@sprunk.org> writes:

> On 19-Mar-12 09:52, Lowell Gilbert wrote:
>> Zero <chefmuetze@web.de> writes:
>>> Thank you!
>> 
>> Note, however, that by printing the addresses, that code may have
>> changed how the compiler would otherwise have stored the variables.
>
> The Uncertainty Principle applied to C?  Good job!

Not a metaphor that would have occurred to me, but cute.

>> This isn't just compiler-dependent; it tends to be very sensitive to
>> optimization, as well.
>
> Indeed; this is a very basic optimization.  Any decent compiler will try
> to eliminate variables, where possible, and to store the ones it can't
> in registers.  Taking the address of a variable, though, forces that
> variable to be stored in memory.

Agreed, but I was getting at a bit more than that.  Even once the
variable has been forced into memory by using the '&' operator,
different kinds of optimizations may well result in it being stored 
at different places in memory.

This isn't a pedantic issue; it's commonplace to see a memory map
change when you recompile with different options. It's only a
problem if you forget to pick up the new map, but it *does* mean the
map may change in ways the programmer can't always work out from
first principles. Fortunately, the compiler can usually be convinced
to tell you.

-- 
Lowell Gilbert, embedded/networking software engineer
	 http://be-well.ilk.org/~lowell/

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

addresses of variables Zero <chefmuetze@web.de> - 2012-03-18 03:56 -0700
  Re: addresses of variables "BartC" <bc@freeuk.com> - 2012-03-18 11:18 +0000
  Re: addresses of variables jt@toerring.de (Jens Thoms Toerring) - 2012-03-18 11:18 +0000
  Re: addresses of variables pete <pfiland@mindspring.com> - 2012-03-18 07:30 -0500
    Re: addresses of variables Zero <chefmuetze@web.de> - 2012-03-18 04:42 -0700
      Re: addresses of variables Lowell Gilbert <lgusenet@be-well.ilk.org> - 2012-03-19 10:52 -0400
        Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-19 12:55 -0500
          Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-19 14:30 -0400
            Re: addresses of variables jacob navia <jacob@spamsink.net> - 2012-03-19 20:11 +0100
              Re: addresses of variables hoganlong@gmail.com - 2012-03-19 12:17 -0700
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-19 16:15 -0400
                Re: addresses of variables hoganlong@gmail.com - 2012-03-19 14:18 -0700
                Re: addresses of variables "io_x" <a@b.c.invalid> - 2012-03-19 23:26 +0100
            Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-20 03:52 -0500
              Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-20 06:00 -0400
                Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-20 16:47 -0500
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-20 18:37 -0400
                Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-21 17:58 -0500
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-21 20:24 -0400
                Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-21 23:53 -0500
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-22 06:22 -0400
                Re: addresses of variables Kenneth Brody <kenbrody@spamcop.net> - 2012-03-22 12:01 -0400
                Re: addresses of variables Stephen Sprunk <stephen@sprunk.org> - 2012-03-24 16:09 -0500
                Re: addresses of variables Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-23 13:41 +0100
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-23 09:06 -0400
                Re: addresses of variables Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-23 19:47 +0100
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-23 16:04 -0400
                Re: addresses of variables Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-24 00:19 +0100
                Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-23 22:20 -0400
                Re: addresses of variables Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-24 09:39 +0100
            Re: addresses of variables Anders Wegge Keller <wegge@wegge.dk> - 2012-03-20 20:02 +0100
              Re: addresses of variables James Kuyper <jameskuyper@verizon.net> - 2012-03-20 15:18 -0400
                Re: addresses of variables Anders Wegge Keller <wegge@wegge.dk> - 2012-03-21 21:37 +0100
          Re: addresses of variables Lowell Gilbert <lgusenet@be-well.ilk.org> - 2012-03-20 11:52 -0400
            Re: addresses of variables Kenneth Brody <kenbrody@spamcop.net> - 2012-03-21 11:04 -0400

csiph-web