Re: 2D-array of pointers, set all to null?
On Jul 14, 4:42 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
James Kanze wrote:
I think you've got that a little backwards. I don't know
every system around, and neither do you. So on what basic
do you say that it will work in practice? On a guarantee in
the standard? On some set of "reasonable assumptions" about
what an implementation can or might do? Or on what?
The standard doesn't guarantee a lot of things, yet it may
still be reasonable to expect them anyways. For example, the
standard doesn't guarantee that argv[0] actually contains
something. However, it's still reasonable, in *practical*
systems, to expect something to be there.
The standard actually does guarantee "something" in argv[0],
just not what you might want. And of course, if you want to use
it in portable code, you have to jump through some hoops, not
because of the standard, but in this case, because almost no
implementation is really conform.
In fact, what you can count on in argv[0] is what you've gotten,
historically. And historically, memset didn't work for nulling
pointers, so you can't argue historical tradition for it.
My point is: if you want some (more or less) guarantee beyond
what the standard gives, you need to base it on some reason.
The fact that it works on a couple of widespread implementations
is not sufficient. Given the number of implementations I've
seen and heard of, if I'd never heard of an implementation where
it didn't work, I'd perhaps consider it (although I'm not sure);
given that I've actually heard of implementations where it
didn't work, obviously, you can't use that reason, regardless of
whether it is acceptable. (An example of where I would accept
that reason:
std::vector< char > v ;
int ch = std::cin.get() ;
while ( ch != EOF && ch != '\n' ) {
v.push_back( ch ) ;
}
Implementation defined, according to the standard, and the C
standard even explicitly mentions the possibility of an
implementation defined signal. However, given that no
implementation has, to my knowledge, made it fail *AND* given
that this is just a rewrite of the basic way K&R said to do
character input, back in the first edition of the C book, and
that the idiom is enormously widespread, among extremely
competent people, I think it's probably safe to say that no
implementation would dare break it. But there are a lot of
conditions involved.
You could raise the argument that using memset to set pointers
to null is widespread, and thus, implementations won't dare to
break it. Except that they have in the past, so apparently, it
wasn't widespread enough. And it's a very valid implementation
technique on some architectures. (Come to think of it, I rather
doubt that it would work on a Unisys MCP. There's a tag bit in
their words, and I sort of think that it has to be 1 if the word
is a pointer.)
--
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