8000 GitHub - fietec/dynarray.h: A simple header-only c library for creating dynamic arrays of any specific type
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple header-only c library for creating dynamic arrays of any specific type

License

Notifications You must be signed in to change notification settings

fietec/dynarray.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

dynarray.h

A simple header-only c library for creating dynamic arrays of any specific type.

The header file consists of a singular macro which creates the data structure and corresponding functions for:

  • creating
  • pushing a value
  • printing a reprensentation (customizable with function pointer for value printing)
  • freeing the allocated memory (customizable with function pointer for value freeing)

How to use

  #include "dynarray.h" // include the header file

  DEFINE_DYNAMIC_ARRAY(Ints, int) // define the dats structure and its functions with a name (here 'Ints') and the type of the stored values (here <int>)

  int main(void)
  {
    Ints* ints = Ints_create(16); // create the dynamic array of type Ints with a initial capacity of 16
    for (size_t i=0; i<18; ++i){
      Ints_push(ints, i); // push a value to the dynamic array
    }
    /*either*/ Ints_print(ints, NULL); // print a representation of the dynamic array with placeholders for the values
    /*or*/     Ints_print(ints, &print_my_type); // print a reprensentation of the dynamic array with a custom function printing the value

    /*either*/ Ints_free(ints, NULL); // free the memory allocated for the dynamic array and ignore the stored values
    /*or*/     Ints_free(ints, &free_my_type); // free the memory allocated for the dynamic array and use a custom function for freeing the memory of the stored values
    
    return 0; // heard that's a good idea..
  }

About

A simple header-only c library for creating dynamic arrays of any specific type

Topics

Resources

License

Stars

Watchers

Forks

Languages

0