Changes in src/examples/alloc.c [784deab:d3b7937]
- File:
-
- 1 edited
-
src/examples/alloc.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/alloc.c
r784deab rd3b7937 1 #if 0 1 2 extern "C" { 2 3 typedef long unsigned int size_t; … … 15 16 return (T *)calloc( size, sizeof(T) ); 16 17 } 18 #endif 19 typedef int size_t; 17 20 forall( type T ) T * realloc( T *ptr, size_t n ) { 18 return (T *)(void *)realloc( ptr, sizeof(T) );21 // return (T *)(void *)realloc( ptr, sizeof(T) ); 19 22 } 20 forall( type T ) T * realloc( T *ptr, size_t n, T c ) {21 return (T *)realloc( ptr, n );22 }23 //forall( type T ) T * realloc( T *ptr, size_t n, T c ) { 24 // return (T *)realloc( ptr, n ); 25 //} 23 26 24 int *foo( int *p, int c );25 int *bar( int *p, int c );26 int *baz( int *p, int c );27 //int *foo( int *p, int c ); 28 //int *bar( int *p, int c ); 29 //int *baz( int *p, int c ); 27 30 28 31 int main( void ) { 29 size_t size = 10; 30 int * x = malloc(); 31 x = malloc(); 32 x = calloc( 10 ); // calloc: array set to 0 33 x = realloc( x, 10 ); 34 x = realloc( x, 10, '\0' ); 35 x = malloc( 5 ); 36 float *fp = malloc() + 1; 32 // size_t size = 10; 33 //int * x = malloc(); 34 int * x; 35 // x = malloc(); 36 // x = calloc( 10 ); // calloc: array set to 0 37 // x = realloc( x, 10 ); 38 // x = realloc( x, 10, '\0' ); 39 // x = malloc( 5 ); 40 // float *fp = malloc() + 1; 37 41 38 42 struct St1 { int x; double y; }; 39 43 struct St1 * st1; 40 double *y;44 // double *y; 41 45 x = realloc( st1, 10 ); // SHOULD FAIL!! 42 46 #if 0
Note:
See TracChangeset
for help on using the changeset viewer.