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