Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/alloc.c

    rd3b7937 r784deab  
    1 #if 0
    21extern "C" {
    32    typedef long unsigned int size_t;
     
    1615    return (T *)calloc( size, sizeof(T) );
    1716}
    18 #endif
    19 typedef int size_t;
    2017forall( 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) );
    2219}
    23 //forall( type T ) T * realloc( T *ptr, size_t n, T c ) {
    24 //    return (T *)realloc( ptr, n );
    25 //}
     20forall( type T ) T * realloc( T *ptr, size_t n, T c ) {
     21    return (T *)realloc( ptr, n );
     22}
    2623
    27 //int *foo( int *p, int c );
    28 //int *bar( int *p, int c );
    29 //int *baz( int *p, int c );
     24int *foo( int *p, int c );
     25int *bar( int *p, int c );
     26int *baz( int *p, int c );
    3027
    3128int 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;
    4137
    4238    struct St1 { int x; double y; };
    4339    struct St1 * st1;
    44 //    double *y;
     40    double *y;
    4541    x = realloc( st1, 10 );                             // SHOULD FAIL!!
    4642#if 0
Note: See TracChangeset for help on using the changeset viewer.