Skip to content

Generic Vector/Dynamic Array implementation using Macros in C.

Notifications You must be signed in to change notification settings

alexiszamanidis/vector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vector

Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.

vector

Macro

A macro is a name given to a block of C statements as a pre-processor directive. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main () function). A macro is defined with the preprocessor directive, #define.

Advantages of using macro

  1. The speed of the execution of the program is the major advantage of using a macro.
  2. It saves a lot of time that is spent by the compiler for invoking / calling the functions.
  3. It reduces the length of the program.
    /* MACROS */
    #define vector(datatype)
    #define vector_init(vector)
    #define vector_expand(vector,expand)
    #define vector_push_at_nth_position(vector, value, position)
    #define vector_push_front(vector, value)
    #define vector_push_back(vector, value)
    #define vector_erase_from_nth_position(vector, position)
    #define vector_erase_front(vector)
    #define vector_erase_back(vector)
    #define vector_at(vector, index)
    #define vector_clear(vector)
    #define vector_for_each(vector, value)

Unit Testing

CUnit is a lightweight system for writing, administering, and running unit tests in C. It provides C programmers a basic testing functionality with a flexible variety of user interfaces.

Instalation instructions

    $ sudo apt-get install libcunit1-dev libcunit1-doc libcunit1

Execution instructions

Run all the tests

    $ cd tests/scripts
    $ ./run_tests.sh

Run demo

    $ cd source
    $ make
    $ valgrind ./vector

About

Generic Vector/Dynamic Array implementation using Macros in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published