--
Chung Ha-nyung <al...@kldp.org>
something like:
char* stack_base = NULL;
int main()
{
char x;
stack_base = &x;
...
}
int getStatckSize()
{
char x,
*xx = &x;
return xx - stack_base;
}
...but this is neither standard nor portable.
Radoslav Getov
rge...@ultraheap.com
On most architectures that would be the other way
around because stacks grows downwards from top of
memory.
BTW It could be simplified a little:
int getStackSize()
{
char x;
return stack_base-&x;
}
> }
>
> ...but this is neither standard nor portable.
Except from the direction in which stacks grow I
think it is very portable. I tried it on IRIX,
Solaris, and Linux. (I will try it on my Amiga
some day. ;-) )
--
Kasper Dupont -- der bruger for meget tid på usenet.
For sending spam use mailto:razor-...@daimi.au.dk
> Can I get the usage of stack in a process(or thread)?
Don't know if this is what you mean exactly, but this can be used
to give the address of the stack pointer:
int main( void )
{
unsigned long * spaddr;
asm( "movl %%esp, %%eax;
movl %%eax, %0;"
:"=r"(spaddr)
:
:"%eax" );
printf("stack address: 0x%x\n", spaddr);
}
--
J o s h u a J o n e s *** email: jajones(at)cc.gatech.edu
__ .~.
College of Computing at the | / / _ _ _ _ _ __ __ /V\
Georgia Institue of Technology | / /__ / / / \// //_// \ \/ / // \\
Atlanta, Georgia, U.S. | /____/ /_/ /_/\/ /___/ /_/\_\ /( )\
*Debian GNU/Linux* ^^-^^