i'm writing a program which can accept switches to set various things in
the program, there will be several switches (all optional) which set
some conditions in my program to either ON or OFF. To process this i was
going to:
declare a struct like this:
struct {
unsigned int file : 1; /* input from file or stdin? */
unsigned int today : 1; /* use today's date? */
...
} flags;
munch through **argv looking weather the switches are present
if they are, set the relevant things in the struct to 1, if they aren't
present, set them as zero (or init the flags struct to all zeros to start
off with, then just set the switches that are given to 1).
then in the relevant parts of the program, check if a bit was set, if it
was, do foo, if it wasn't set, do bar... etc.
anyone see a problem with this? i'll just be accessing the flags thing
like a regular struct.. i.e if (flags.file == 1) { fopen (...) } else {
fgets (stdin) };
i could use whole ints for each flag, but why waste an entire (sizeof
(int)) when i am only setting things on or off, using bits seems more
logical...