All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Ramos <fabiano.ramos@gmail.com>
To: "John Anthony Kazos Jr." <jakj@j-a-k-j.com>
Cc: Rajat Jain <rajat.noida.india@gmail.com>,
	kernelnewbies <kernelnewbies@nl.linux.org>,
	newbie <linux-newbie@vger.kernel.org>
Subject: Re: kernel stack problem
Date: Wed, 04 Apr 2007 00:19:55 -0300	[thread overview]
Message-ID: <1175656795.4689.19.camel@core2duo.localdomain> (raw)
In-Reply-To: <alpine.DEB.0.83.0704032150010.10010@sigma.j-a-k-j.com>

On Tue, 2007-04-03 at 21:51 -0400, John Anthony Kazos Jr. wrote:
> > This is wrong. Although the scope is at _block_ level, all variables are
> > allocated on the stack at _function_ level. So, when entering func() all
> > variables within it, including x and y, are allocated.
> 
> But this doesn't make sense. Why would the compiler not immediately 
> optimize both variables into the same allocation? It seems obvious to me 
> that the amount of space pushed onto the stack when the function is 
> entered should be the maximum space needed by any combination of local 
> variables in-scope at any time. GCC wouldn't be that stupid, would it?


Yes, I agree. But take a look...
 
00:19:01 framos@core2duo:~ $> more teste.c
#include <stdio.h>

int main()
{
   {
   int x=5;

   printf("x=%d\n",x);
   printf("addr(x)=%p\n", &x);

   {
      int y=10;
      
      printf("y=%d\n",y);
      printf("add(y)=%p\n", &y);
   } 

   return 0;
}
 
00:19:04 framos@core2duo:~ $> ./teste
x=5
addr(x)=0xbf8b0b00
y=10
add(y)=0xbf8b0afc
00:19:06 framos@core2duo:~ $> 



-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

  reply	other threads:[~2007-04-04  3:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-04  0:50 kernel stack problem Rajat Jain
2007-04-04  0:57 ` Fabiano Ramos
2007-04-04  1:51   ` John Anthony Kazos Jr.
2007-04-04  3:19     ` Fabiano Ramos [this message]
2007-04-04  3:25     ` Fabiano Ramos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1175656795.4689.19.camel@core2duo.localdomain \
    --to=fabiano.ramos@gmail.com \
    --cc=jakj@j-a-k-j.com \
    --cc=kernelnewbies@nl.linux.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=rajat.noida.india@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.