Good $daytime,
Happy New Year to all!
> Date: Sat, 2 Jan 1999 02:05:51 +0000 (GMT)
> From: "James [on his mailserver]" <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: bits
> 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...
Then you (well, your compiler) will waste at least three extra words
upon each (unoptimized) access to such members.
Second, C++ standard does NOT warrant that struct uses precisely that
amount of bits, rounded up to 8. This claimed to be
implementation-dependent. However, with GCC it works, but what about
portability?
Third, in nowadays RAM, one sizeof(short) is hardly a waste. IMHO
your approach is good when you develop protocols to work over
low-bandwidth links, but with internal data structures that's not the
case.
Another point, esp. in processing command-line options, is to have
third (unassigned) state for each flag so you'll be able to catch up
with multiple or contradictory specifications.
Regards,
Willy.
--
"No easy hope or lies | Vitaly "Willy the Pooh" Fedrushkov
Shall bring us to our goal, | Information Technology Division
But iron sacrifice | Chelyabinsk State University
Of Body, Will and Soul." | mailto:[EMAIL PROTECTED] +7 3512 156770
R.Kipling | http://www.csu.ac.ru/~willy VVF1-RIPE