Re: C++0x: New function syntax; opportunity to fix arrays?
On Sep 16, 4:16 pm, Vidar Hasfjord <vattilah-gro...@yahoo.co.uk>
On Sep 16, 12:16 am, Braden McDaniel <braden.mcdan...@gmail.com>
(Aside: C++ know how to copy arrays. It is required to copy a struct
in which an array is a member; this is why you can create wrappers,
like std::array, that simulate perfect arrays.)
I agree with you 100%. I am glad you have ressurected this topic in
the context of C++0x.
IMHO, this irregularity, carried over from C, is _THE_ largest anomaly
of C and C++. Perhaps Denis Ritchie thought he was doing us a favor
by automatically decaying the name of the array to a pointer. "After
all...", he might have said, "...certainly, when one specifies an
array as argument to function, surely they will not intend to pass the
entire array." I think it would have been better to heed the maxim:
"When in doubt, keep it regular."
Also, the not treating arrays like scalars and aggregates eliminates a
useful opportunity for efficiency in copying. Suppose we have:
typedef char Key;
Rijndael::Key a1, a2;
a1 = a2; // sorry, cannot do this.
To achieve assignment, we have to resort to other trickery, like
encasing arrays in structs, as you pointed out, or using platform-
specific compiler flags for "intrisics", etc. If treatment of arrays
were regular, we would be guaranteed the fastest available method of
copying under all conditions, while maintaining strict portability.
It must be noted also, that if Dennis Ritchie had decided to, keep
arrays regular, there would have been no loss in the feature-space of
C. The only thing we have gained is being able to write:
This ability is hardly worth a breach of regularity.
If there were a vote today among C++ community to decide if a full-
fledged change be made to C++ to correct this situation, I would be
among the first to cast my "YES" vote.
There are some situations where the new is so much more correct than
the old that disregard for backward compatibility is warranted. IMHO,
this is one of them.
-Le Chaud Lapin-
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]