To Walter, about char[] initialization by FF
Andrew Fedoniouk
news at terrainformatica.com
Tue Aug 1 23:45:26 PDT 2006
> But maybe that's because I never leave things at their defaults. It's
> like writing a story where you expect the reader to think everyone has
> brown eyes unless you say otherwise.
>
Consider this:
char[6] buf;
strncpy(buf, "1234567", 5);
What will be a content of you buffer?
Answer is: 12345\xff . Surprise? It is.
In modern D reliable implementation of this shall be as:
char[6] buf; // memset(buf,0xFF,6); under the hood.
uint n = strncpy(buf, "1234567", 5);
buf[n] = 0;
if you are going to use this with non D modules.
Needless to say that this is a bit redundant.
If D in any case initializes that memory why you need
this uint n and buf[n] = 0; ?
Don't tell me please that this is because your spent
your childhood in boyscout camps and got some high principles.
Lets' put aside that matters - it is purely technical discussion.
Andrew.
More information about the Digitalmars-d
mailing list