Re: How to get total heap size of a process



Andrew Poelstra wrote:

.... snip ...

int main(void)
{
/* puzzle. Why will this code break if we make a x a size_t ? */
unsigned long x = 0;

while(malloc(1))
x++;
printf("You have %lu bytes available\n", x);
return 0;
}

Because printf can't handle a size_t?

Exactly. You should cast x to (unsigned long). This will work on
C90 systems, provided only that an unsigned long can express a
size_t. For C99 you can use %z (I think).


--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.


.



Relevant Pages

  • Re: c interview
    ... undefined behaviour because printf is a varidac function. ... stdio.h before using printf and other headers as appropriate before ... Would make it a point that the size of int is assumption to be .... ...
    (comp.lang.c)
  • Re: Confused to printf %f
    ... Someone asked me a question about integer division and printf ... You gave it an int. ...
    (comp.lang.c)
  • Re: First program in C - what is going on with function returns?
    ... The program is compiling ok but I receive this warning: ... char *speakdate(int d, int m, int y) ... printf ("Your date of birth is ...
    (comp.lang.c)
  • Re: Printf
    ... "pete" wrote in message ... >> If you have an integer, how to print it out without using printf? ... > int fsput_u ...
    (comp.lang.c)
  • Re: OT: Warning--our country is changing!
    ... But I'll go on the record saying ... bad for the country when authority-dependent toadies start raising the ... You actually hate this country enough that you'd want to be a part ...
    (alt.guitar.amps)