@George P: Go ask a new which they find easier to learn the how & why of low level programming, the C "Hello World!" or the C++ "Hello World!", I'm sure you'll find most of them call C++ confusing (the thing it set out to not be, ironic huh?) while calling C frustrating but at least understandable to some extent. Yes macros can sometimes be a problem but that's usually because the developer didn't make the macro from tested code, nor make it small enough, let's take the simple rotation macros rol & ror (may have mis-remembered their names) as an example. Now one could feasibly implement the macro in one line but for arguments sake, let's say we want the expression to be debuggable, a simple modification would look like this:
Declaration:
1 2
|
uintmax_t _rol( uintmax_t a, size_t b, size_t size );
#define rol( a, b ) _rol( a, b, sizeof(a) * CHAR_BIT )
|
Implementation:
1 2 3 4 5 6 7 8 9
|
uintmax_t _rol( uintmax_t a, size_t b, size_t bits )
{
uintmax_t keep = ~(((uintmax_t)~0) << bits);
uintmax_t left, right;
b %= bits;
left = a << b;
right = a >> (bits - b);
return keep & (left | right);
}
|
Now sure it doesn't look pretty, nor is it as flexible as the one line expression it normally is but it gets the job efficiently while also being understandable to newbies, now as for the c++ implementation, it would still use a macro because not even it's template system allows it to just skip the type, for example:
Declaration:
|
T rol<T>( T a, size_t b );
|
Implementation:
1 2 3 4 5 6 7 8
|
T rol<T>( T a, size_t b )
{
T left, right;
b %= bits;
left = a << b;
right = a >> (bits - b);
return left | right;
}
|
A newbie won't necessarily know that <T> refers to a template and <T> is not exactly easy to google, if they're not being taught by someone directly then they might just think they're not smart enough to learn c++ and just give up at the first problem, since when is encouraging that mindset in newbs who can't afford lessons the "best practice" for any programming language? That's just elitism at that point, and we ALL know elitists are pricks who do NOT deserve to be in any community, which is precisely why I stop short of calling C the be all & end all of low level programming. Every language has it's pros & cons, to me the obfuscated mess that c++ has become is a con so big it is not worth using as my main, I'll happily wrap my functions and structures up with classes that hide the passing of the structure pointers but using c++ to develop the bulk of my code has become a big no no to me, it's like adding oil to water, it just does not belong.