Subject: Re: sbrk behaviour..!
To: BALA <BKUMARES.IN.ORACLE.COM.ofcmail@in.oracle.com>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: port-i386
Date: 07/21/1997 13:31:54
> main() {   /* blank lines compressed out --Mouse */
> char *str; 
> str=sbrk(0); 
> printf("%d \n",str); 
> str=sbrk(0); 
> printf("%d \n",str); 
> } 

> My problem is I get different values printed for the two printf
> statements.  If I continue to do 'sbrk(0)' and print the base address
> its the same as what got printed the second time.

> Why is this ?

My first guess was that it's because you're using %d to print a char *.
Then I noticed you sent it to port-i386 and thus are presumably trying
this on an Intel processor, which is so short of registers that it
isn't going to be going overboard passing arguments in registers,
though if it did it might well use a different register for an int or a
pointer (doesn't the x86 have typed registers to some extent?)>

What is almost certainly the _real_ reason is that the first call to
printf involves stdio doing some malloc()ing; malloc then calls sbrk to
get its underlying memory, which is the growth you're seeing.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B