This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/sbrk.c

34 lines
833 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#if defined( _M_I86 )
#define alloc( x, y ) sbrk( x ); y = sbrk( 0 );
#else
#define alloc( x, y ) y = sbrk( x );
#endif
void main()
{
void *brk;
#if defined( _M_I86 )
alloc( 0x0000, brk );
/* calling printf will cause an allocation */
printf( "Original break value %p\n", brk );
printf( "Current amblksiz value %x\n", _amblksiz );
alloc( 0x0000, brk );
printf( "New break value after printf \t\t%p\n", brk );
#endif
alloc( 0x3100, brk );
printf( "New break value after sbrk( 0x3100 ) \t%p\n",
brk );
alloc( 0x0200, brk );
printf( "New break value after sbrk( 0x0200 ) \t%p\n",
brk );
#if defined( _M_I86 )
alloc( -0x0100, brk );
printf( "New break value after sbrk( -0x0100 ) \t%p\n",
brk );
#endif
}