Re: array size known/not known in compile time
* James Kanze:
Alf seems to be
willing to put his money where his mouth is, and to do at least
some of the work necessary to come up with an acceptable
proposition,
Money? What money? <g> Wish I had, but although committee work is not
economically possible for me[1] -- someone would have to "sponsor"
this in the committee -- I can contribute some time & effort.
When I fixed up the spec[2] code I presented earlier so that it passed
compilation[3], I found three things requiring compiler support:
A Detecting the context the DSA (Dynamically Specified Array) is used
in.
E.g., for Visual C++ dynamic stack allocation is UB in a 'catch', so
within a Visual C++ 'catch' it must be replaced with ordinary
slow dynamic allocation (I bet many a programmer has fallen into the
trap of using MS's charset conversion macros within 'catch'! --
support for DSAs would help to remove that bug-attractor).
Also, it would be catastrophic to use it at namespace scope.
B Doing the stack allocation in the proper call context.
For the code I had to define macros that allocate and pass a pointer
to the allocated memory to the dynspec_array constructor.
This problem could alternatively, possibly, be solved by allowing
formal arguments to have defaults specified in terms of earlier
arguments, but that would seemingly require a well-defined specified
order of evaluation (which we all want, but, seemingly, for some
reason nobody dares to put it to the committee).
C Support initializer lists.
Definining an AND macro for the comma is a kludge. Perhaps Andrei
knows some super-duper solution, but I sure don't. Anyway, when it
can't be done without using macro evilness, language support is
indicated.
If not for this, and perhaps other things I haven't encountered or
thought of so far, a library solution could probably be a "good enough"
solution. So there is a strong connection to the thread on the D
language, what can reasonably be implemented as library solutions.
Perhaps more problems requiring language support will pop up when or if
I try to add multi-dimensional support; so far it's single-dimension.
Notes:
[1] I play the guitar because I could never afford a keyboard. In my
teens I bicycled to secondary school, some 20 miles?, to use the
electronic organ there. I also wanted to do electronics, but,
unable to afford that hobby, except by experimenting with bits and
pieces salvaged from old radios & donated to me by a radio
amateur (a friend of my father), I ended up programming, which if
need be can be done on paper -- and I did that.
[2] <url: http://preview.tinyurl.com/ycb9x7>
[3] <url: http://home.no.net/alfps/misc/dsa/v0_spec_test.cpp>
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]