Anybody has any idea about how to define a mathematical set in C (like
the Pascal one SET ... OF ...) with operations like union,
intersection, pertenence ...
Normally this is done with a bitmap. You assign each member of
the set to a bit. Then union can be taken with the | operator,
intersection with &. I don't know what "pertenence" is.
Here's a worked example. Suppose you have a set of fruit that
might contain an apple, an orange, or a pear. Then give each of
those a bit:
#define APPLE (1u << 0)
#define ORANGE (1u << 1)
#define PEAR (1u << 2)
unsigned basket1 = APPLE; /* Just an apple. */
unsigned basket2 = ORANGE | PEAR; /* An orange and a pear. */
unsigned both_baskets = basket1 | basket2; /* Union. */
/* Is there an apple in basket2? */
if (basket2 & APPLE) { ... }
/* Remove an orange from basket2. */
basket2 &= ~ORANGE;
....etc...