eteran / c-vector

A dynamic array implementation in C similar to the one found in standard C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why while(0)

mmj-the-fighter opened this issue · comments

Please explain the rationale behind keeping the following pattern in the code
do{
...
} while (0)

i replaced do{ ... } while(0) with {..} for #define cvector_push_back(vec, value) , and it worked.

The rationale is that it is a common pattern to ensure that the code properly acts like a function call.

For example, you'll notice that the do while version requires a semicolon but yours does not.