Frinos said:
Sorry for the previous top post, (I'm sure you can excuse first time
posters!!.... )...
I can
Another thing - please quote some context in your messages. You've
replied to various of my points here, but you haven't included any of
what I said. Someone reading your message won't know what you're
referring to.
To quote from Google, don't use the Reply button. Click Show Options at
the top, then use the Reply option revelaed there.
With regards to using CAPS, there are no do's and dont's.... it's just
preference and following your coding standards....
Yes, my "don't" was meant as advice. Clearly if you are following
someone else's coding standards (your employer for example) you do what
they say. But if you are writing code under your own rules it is a very
good idea to invent a 'namespace' convention for macros to protect your
code. ALL_CAPS for macros is the only widespread convention I've
encountered.
With regards to declaring the array I suppose its bad use of words on
my part, maybe I should have used the word "create" rather than
declare.....
In one case you declare the array (which also creates it... double
Array[10])..... In the other case, you declare a pointer to a double
and assign
initialise, not assign
it with the address of the first element of the "newly"
created array... double* pArray = new double[10]).... In both cases an
array is created but the important thing to note is that with the first
array, its memory is reserved during compilation and with the other
array, it is created dynamically at run time and therefore the memory
reserved for it must be deleted...
I suspected you understood what you were saying, but I made the
correction for the benefit of the OP and anyone else reading your post.
Confusion between arrays and pointers is a common problem in learning
C++. That sort of correctness is highly valued here.
I corrected your 'assign' to 'initialise' for the same reason.
Assignment and Initialisation are precisely defined concepts in C++ and
mixing them up can be another source of confusion in learning the
language.
With regards to array deletion your statement is not necessarily the
case, delete can be used just as well as delete[] when used with the
new[] operator...... It all depends on your compiler and if it allows
it. I think the C++ standards have changed in this area..... I use
MSVC++6.0 and does not give me errors or undefined behaviour, but I do
guess its better to get into the habit of using delete[] with new[]...
Unless the rules have changed in C++03 (which I highly doubt), then my
statement is correct. new [] paired with delete *is* illegal and it
does cause undefined behaviour. new [] has to go with delete [] and new
has to go with delete. Incidentally, VC++6 is a very old compiler - it
predates even the original C++ standard from 1998 and is non-conformant
in a lot of respects.
Undefined Behaviour means *absolutely anything* can happen. The program
could crash, it could add 1 to all the int variables currently in
existence, it could print rude messages on the screen, it could
reformat your hard drive. Or it could do exactly what you expected it
to do. You were unlucky and happened to get the last example.
Gavin Deane