Re: Future of C++
On Aug 15, 12:02 pm, Ian Collins <ian-n...@hotmail.com> wrote:
James Kanze wrote:
On Aug 15, 9:50 am, Ian Collins <ian-n...@hotmail.com> wrote:
Pavel wrote:
But guess (honestly, without trying), what the following
trivia will print:
#include <streamline>
#include <string>
using namespace std;
int main(void) {
string a = "35" + 2;
The address of the string literal "35"+2, which will be
'\0'.
You've got considerable C experience as well:-).
Not really, only about 28 years :)
You beat me by two.
(compiles and run without a warning on my cygwin, g++
3.4.4).
As it should.
According to the C++ standard. Whether that's a good thing
or not is debatable.
But in this case, the string literal decays to a const char*,
so no type checking rules are broken.
None according to the language standard. In this case, I'd
argue that it is the language which is broken; an array is NOT a
pointer, and it shouldn't implicitly convert to one. Of course,
changing this would break C compatibility and so much existing
code we can't even conceive of it, but it is clearly a design
flaw in the original C (probably present because that's the way
it worked in B, where it actually made sense).
Pavel's right about this one: it shouldn't compile in any
language which is statically typechecked. (In more dynamic
languages, of course... ` print "35" + 2 ' prints 37 in AWK.
As well as every scripting language I know.
Supposing the scripting language supports numeric addition.
(Historically, the Bourne shell didn't, and I've still the habit
of using expr, instead of ((...)).)
Which is what I would expect, given the total absence of
typing. Which is fine for small projects---I regularly use
AWK for up to around 500 lines of code---but doesn't scale
well.)
Try PHP, I'm in the middle of a several thousand line
PHP/JavaScript application at the moment. The lack of type
checking is both liberating and dangerous.
Exactly. I'm not familiar with PHP or JavaScript, because my
networked machines talk to other machines, not people (through
browsers), but I do do a lot of scripting, in addition to C++.
It's the glue which holds things together.
Thank goodness for unit tests, they take the place of the
compiler!
True, but a unit test failing isn't quite as good as a compiler
error message in such cases.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34