xx
C lets you blur the distinction between ** and *[ ] and [ ][ ]
rather more, especially in function calls.
void foo(char a[2][2]) {
// do nothing
}
int main(void) {
char** a;
foo(a);
return 0;
}
will cause most C++ compilers to abort, as in C++ there's no possible
conversion from char** to *char[2].
A C compiler will typically complain but compile it anyway, perhaps since
there is often a practical way to perform the conversion.
Not really. On most (flat-addressed) machines you can 'convert' one
(data) pointer type to any other but it's still pointing to the wrong
thing. If you never use the result, as in your example, _that_ almost
always 'works' -- or can be made to by a cast. In neither language
does it work in the sense of being useful for anything.
On average and especially in the past C compilers have been more
permissive about 'ignoring' errors -- or rather, C++ compilers have
mostly deliberately been more restrictive. But this is not inherent in
either language; it is due more to the attitudes of the (groups of)
people who developed them early, leading to shared expectations, then
traditions (cue Tevye) that might reasonably be called cultures.
This may simply be a QOI issue or a case of getting overchummy with the
implementation. But I've come across this in real live production code
written by 3rd parties of great eminence.
If _this_ code was "live" -- i.e. actually executed and the result(s)
used -- I have trouble believing that. Depending on which sides write
and read, it should produce grossly wrong results or crash or at
"best" clobber memory that will likely break something else.
Now, I've seen lots of bogus code in production programs either not
used at all (cancelled or mistaken) or once used but obsoleted by
changes elsewhere, that people haven't fixed or removed because it
"isn't broken". Which isn't necessarily wrong; in some environments
there is a high cost to re-testing/validating _any_ production change,
no matter how small or "obvious"; cost and risk in deploying; and even
risk of breaking workarounds or adaptations. If the code is wrong but
not actually causing problems it can be worth living with it.
- David.Thompson1 at worldnet.att.net