Re: memory trampling
On Oct 21, 5:31 pm, Zeppe
<ze...@remove.all.this.long.comment.yahoo.it> wrote:
joshuajnoble wrote:
I threw together a quick test here, I'm thinking my problem
is in what I'm doing with the static pointer (perhaps).
Here's my Singleton:
I'm not sure, I can't see major problems in this piece of code.
[...]
val2 = "abcdefghijklmn";
this is maybe val2[0] = "..."; otherwise, it won't compile.
I'd count that as a major problem, since it means that he's not
posting the actual code which causes the problem.
However, it will give you warning anyway regarding the
conversion from const char* (the string literal) to char*.
The standard doesn't require warnings:-). As a quality of
implementation issue, of course, a good compiler should give the
warning. Provided you've invoked it as a good C++
compiler---every compiler I know needs a half a dozen options to
be truly a C++ compiler.
[...]
Surely inst is initialised somewhere to NULL, as in
SingletonImpl* SingletonImpl::inst = NULL;
or similar. Otherwise it won't link.
You don't actually need the initialization, since objects with
static lifetime are zero initialized anyway. But without the
definition, it's undefined behavior---with the compilers I
usually use, it won't link either, but the standard doesn't
require an error of any sort, and it's quite possible that a
compiler could implicitly supply the definition, but skip the
zero initialization for it. That would still be conforming (but
not really what I would call a very good implementation).
--
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