Shark said:
Yes I agree with you. I am against the use of c++ preprocessor to
define globals (partly because I read Scott Meyers). But the snippet I
was demonstrating was correct in itself (due to closure, i think.
Question satisfied by answer, and answer is to the point). Meep!
Don't know when to quit, do you? (Nor do I, it seems...)
The snippet was correct and solved the immediate problem. However, it
was a lousy solution to the problem because it was excessively
specific, and provided no benefit in exchange for its rigidity. It's
just bad.
If I were to write something like this for my own use, I'd write
exactly what you suggested. But if I am quoting from another
source....and if they have a good reason for writing a macro instead of
function, then ranting is pointless.
It defined a macro, then used the macro in a function. I think you're
getting confused, because there are two issues:
* In C++, it's dumb to use #define for constants, because const is
better.
* In both C and C++, it's dumb to write a function like
"set3rdBit(unsigned char)" rather than "setNthBit(int, unsigned char)."
That has nothing to do with C vs. C++, embedded vs. not, etc. It's
just an idiotic programming practice.
Well, C != C++ obviously, but C is a subset of C++.
No, it's not. C++ has a C-like subset. It's different.
Just because you
are using a C++ compiler shouldn't mean you must use all the WMDs that
C++ provides.
No, but good C code can be bad C++ code. Same code, different context,
yes it really does make a difference.
Lets use some polymorphism to relate C and C++
Please let's not.
Does that mean anywhere you can use C you can also use C++? Sure you
can!
In most cases, a C++ compiler will compile valid C code. But the
matter at hand is not syntactic correctness, but good programming
practice. C++ allows much more effective practices than the
best-of-breed C practices. The bar is higher, so anything which only
comes as high as the bar for C is substantially sub-par in C++.
Does that mean C++ is C? Open question.
Not really. No more so that C++ is arithmetic. Sure, it incorporates
arithmetic. But if all you do is add, subtract, multiply, and divide,
you're kind of missing the point.
Because years of
conditioning by books, professors, and crappy recruiters looking for
"C++ Professionals" has skewed the answer in favor of "no".
Or the fact that, objectively, C++ isn't C.
translates into english as "He that fights and runs away, lives to
fight another day."
Still haven't seen the back of you.
Luke