Re: why does this work with Visual C++ 2005?
On Tuesday, 1 October 2013 02:18:55 UTC+1, K. Frank wrote:
I have a follow-up question:
I do understand that this behavior is (in part)
legacy behavior from the early days of c (maintained,
at least in part, for backward compatibility).
But if we were redesigning c++ from scratch today,
would this behavior make any sense?
No. When the first C++ standard was being developed, there was
a fairly large consensus that C style arrays were broken, and
there was some discussion early on as to whether to fix them,
and if so, how. In the end, it was felt that anything that
would fix them would have to go so far that it would
unacceptably break C compatibility, and that the library could
provide alternatives with the correct behavior.
(Let me ask
this question under the assumption that our new c++
still supports raw arrays, and possibly supports
pointer decay.)
What, for example, would be the clearest way to
explain this to a new student of c++? I, supposedly,
actually know this stuff, and I have a hard time
keeping it straight off the top of my head.
You don't explain it to a new student of C++. Using C style
arrays is an advanced topic, which you probably won't enter into
until you're discussing issues like order of initialization of
static variables, or optimization techniques.
Is this purely a wart on c++ due to backward compatibility
and the long history of c/c++? Or does it actually
make sense (at least in part) when viewed through
modern eyes?
It makes sense in the sense that C++ is designed to allow
calling C interfaces directly. Other than that...
--
James