Changeset d3b7937 for src/examples/alloc.c
- Timestamp:
- Jan 29, 2016, 4:36:39 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- ae8b942
- Parents:
- f3fc8cbe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/alloc.c
rf3fc8cbe 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.