Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #167069
| From | Joe Pfeiffer <pfeiffer@cs.nmsu.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: variable addresses on the stack |
| Date | 2022-08-19 15:47 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <1b35drsy66.fsf@pfeifferfamily.net> (permalink) |
| References | <54f99ed2-fe4d-4cab-944c-cb61799d64ecn@googlegroups.com> |
Thiago Adams <thiago.adams@gmail.com> writes:
> I am curious with the following..
>
> void f(int i) {
> if (i > 1) {
> int j ='a';
> }
> if (i < 1) {
> int k ='b';
> }
> }
> When I see the assembly ouput I can see the compiler
> use the address rbp-4 for j and rbp-8 for k
>
> Why not the same address considering that j and k don't exist
> at the same time?
> Any reason?
Easier to just allocate more space and not keep track of variable
lifetimes. A compiler that was optimizing for space might decide to use
the same location for both.
Likelier would be for an optimizing compiler to notice the function has
no observable behavior and optimize the whole thing away.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
variable addresses on the stack Thiago Adams <thiago.adams@gmail.com> - 2022-08-19 10:22 -0700
Re: variable addresses on the stack Thiago Adams <thiago.adams@gmail.com> - 2022-08-19 10:27 -0700
Re: variable addresses on the stack Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-19 10:59 -0700
Re: variable addresses on the stack Thiago Adams <thiago.adams@gmail.com> - 2022-09-21 05:09 -0700
Re: variable addresses on the stack Thiago Adams <thiago.adams@gmail.com> - 2022-09-21 05:18 -0700
Re: variable addresses on the stack Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-21 15:30 -0700
Re: variable addresses on the stack David Brown <david.brown@hesbynett.no> - 2022-09-21 15:34 +0200
Re: variable addresses on the stack Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-21 15:23 -0700
Re: variable addresses on the stack Kaz Kylheku <480-992-1380@kylheku.com> - 2022-08-19 20:58 +0000
Re: variable addresses on the stack Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2022-08-19 15:47 -0600
Re: variable addresses on the stack Andrey Tarasevich <andreytarasevich@hotmail.com> - 2022-08-19 18:47 -0700
csiph-web