source: translator/examples/vector_int.h @ f7f6785

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since f7f6785 was 134b86a, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

add compiler flag to driver, update examples, fix unnamed bit fields

  • Property mode set to 100644
File size: 935 bytes
RevLine 
[51b7345]1#ifndef VECTOR_INT_H
2#define VECTOR_INT_H
3
[134b86a]4// A flexible array, similar to a C++ vector, that holds integers and can be resized dynamically
[51b7345]5
[134b86a]6typedef struct vector_int {
7    int last;                                           // last used index
8    int capacity;                                       // last possible index before reallocation
9    int *data;                                          // array
10} vector_int;
[51b7345]11
[134b86a]12vector_int vector_int_allocate();                       // allocate vector with default capacity
13vector_int vector_int_allocate( int reserve );          // allocate vector with specified capacity
14void vector_int_deallocate( vector_int );               // deallocate vector's storage
[51b7345]15
[134b86a]16void reserve( vector_int *vec, int reserve );           // reserve more capacity
17void append( vector_int *vec, int element );            // add element to end of vector, resizing as necessary
[51b7345]18
19// implement bounded_array
20
[134b86a]21lvalue int ?[?]( vector_int vec, int index );           // access to arbitrary element (does not resize)
22int last( vector_int vec );                             // return last element
[51b7345]23
[134b86a]24#endif // VECTOR_INT_H
Note: See TracBrowser for help on using the repository browser.