What is predicate in C++?

A predicate is a C++ function returning a boolean or an object having a bool operator() member. A unary predicate takes one argument, a binary takes two, and so on. Examples of questions predicates can answer for a particular algorithm are: Is this element what we are looking for? Is the first of two arguments … Read more

Structure padding and packing

Padding aligns structure members to “natural” address boundaries – say, int members would have offsets, which are mod(4) == 0 on 32-bit platform. Padding is on by default. It inserts the following “gaps” into your first structure: Packing, on the other hand prevents compiler from doing padding – this has to be explicitly requested – under GCC it’s __attribute__((__packed__)), so the following: … Read more

Can I define a function inside a C structure?

No, you cannot define a function within a struct in C. You can have a function pointer in a struct though but having a function pointer is very different from a member function in C++, namely there is no implicit this pointer to the containing struct instance. Contrived example (online demo http://ideone.com/kyHlQ):