extern "C" { typedef long unsigned int size_t; void *malloc( size_t size ); void *calloc( size_t nmemb, size_t size ); void *realloc( void *ptr, size_t size ); void *memset( void *s, int c, size_t n ); void free( void * ptr ); int printf( const char *, ... ); } forall( type T ) T * malloc( void ) { return (T *)malloc( sizeof(T) ); } forall( type T ) T * calloc( size_t size ) { return (T *)calloc( size, sizeof(T) ); } forall( type T ) T * realloc( T *ptr, size_t n ) { return (T *)(void *)realloc( ptr, sizeof(T) ); } forall( type T ) T * realloc( T *ptr, size_t n, T c ) { return (T *)realloc( ptr, n ); } int *foo( int *p, int c ); int *bar( int *p, int c ); int *baz( int *p, int c ); int main( void ) { size_t size = 10; int * x = malloc(); x = malloc(); x = calloc( 10 ); // calloc: array set to 0 x = realloc( x, 10 ); x = realloc( x, 10, '\0' ); x = malloc( 5 ); float *fp = malloc() + 1; struct St1 { int x; double y; }; struct St1 * st1; double *y; x = realloc( st1, 10 ); // SHOULD FAIL!! #if 0 int *p; p = foo( bar( baz( malloc(), 0 ), 0 ), 0 ); free( p ); struct St2 { int x; double y; }; struct St2 * st2; y = malloc(); st1 = malloc(); // st1 = realloc( st2, 10, st1 ); *y = 1.0; printf("%f\n", *y); st1->x = *x + 1; st1->y = *y *1.5; printf("{ %d, %f }\n", st1->x, st1->y); free( y ); x = malloc( 10 ); for ( int i = 0; i < 10; i += 1 ) { x[i] = i * 10; } for ( int j = 0; j < 10; j += 1 ) { printf( "x[%d] = %d\n", j, x[j] ); } free( x ); #endif }