Changeset eab39cd


Ignore:
Timestamp:
Apr 6, 2016, 5:22:45 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
f326f99
Parents:
a5a71d0
Message:

update vector_test to use constructors and destructors

Location:
src/examples
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/examples/vector_int.c

    ra5a71d0 reab39cd  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // vector_int.c -- 
     7// vector_int.c --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:38:05 2015
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 17:18:31 2016
    1313// Update Count     : 3
    1414//
     
    2222#define DEFAULT_CAPACITY 20
    2323
    24 vector_int vector_int_allocate() {
    25         return vector_int_allocate( DEFAULT_CAPACITY );
     24void ?{}( vector_int * vec ) {
     25        vec { DEFAULT_CAPACITY };
    2626}
    2727
    28 vector_int vector_int_allocate( int reserve ) {
    29         vector_int new_vector;
    30         new_vector.last = -1;
    31         new_vector.capacity = reserve;
    32         new_vector.data = malloc( sizeof( int ) * reserve );
    33         return new_vector;
     28void ?{}( vector_int * vec, int reserve ) {
     29        vec->last = -1;
     30        vec->capacity = reserve;
     31        vec->data = malloc( sizeof( int ) * reserve );
    3432}
    3533
    36 void vector_int_deallocate( vector_int vec ) {
    37         free( vec.data );
     34void ^?{}( vector_int * vec ) {
     35        free( vec->data );
    3836}
    3937
  • src/examples/vector_int.h

    ra5a71d0 reab39cd  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // vector_int.h -- 
     7// vector_int.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:39:05 2015
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 17:21:59 2016
    1313// Update Count     : 2
    1414//
     
    2525} vector_int;
    2626
    27 vector_int vector_int_allocate();                                               // allocate vector with default capacity
    28 vector_int vector_int_allocate( int reserve );                  // allocate vector with specified capacity
    29 void vector_int_deallocate( vector_int );                               // deallocate vector's storage
     27void ?{}( vector_int * );                                                               // allocate vector with default capacity
     28void ?{}( vector_int *, int reserve );                                  // allocate vector with specified capacity
     29void ^?{}( vector_int * );                                                              // deallocate vector's storage
    3030
    3131void reserve( vector_int *vec, int reserve );                   // reserve more capacity
  • src/examples/vector_test.c

    ra5a71d0 reab39cd  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // vector_test.c -- 
     7// vector_test.c --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Wed May 27 17:56:53 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 17 12:23:55 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Apr 06 17:19:07 2016
    1313// Update Count     : 18
    1414//
     
    2020
    2121int main( void ) {
    22         vector_int vec = vector_int_allocate();
     22        vector_int vec;
    2323
    2424        // read in numbers until EOF or error
Note: See TracChangeset for help on using the changeset viewer.