To Walter, about char[] initialization by FF

Derek Parnell derek at nomail.afraid.org
Wed Aug 2 01:02:28 PDT 2006


On Wed, 2 Aug 2006 00:08:42 -0700, Andrew Fedoniouk wrote:

>> I think the issue is more that Andrew wants to have hex-FF as a legitimate
>> byte value anywhere in a char[] variable. He misses the point that the
>> purpose of not allowing it in so we can detected uninitialized UTF-8
>> strings at run-time.
>>
> 
> What does it mean uninitialized? They *are* initialized.

Andrew, I will assume you are not trying to be difficult but that maybe
your English is a bit too literal. 

Of course in the clinical sense they are initialized because data is moved
into them before your code has a chance to do anything. However, when I say
"detected uninitialized UTF-8 strings" I mean "detect UTF-8 strings that
have not been initialized by your own code". Is that better?

> This is the main point. For any types you can declare
> initial value. I bet you are choosing not non existent values
> for say enums but some really meaningfull default values.

Huh??? Now you are being difficult. The purpose of enums is to have them
initialized to values that make sense in their context. But the default
values for enum generally work for me as the exact value doesn't really
matter in most cases.

  enum AccountType
  {
     Savings,
     Investment,
     FixedLoan,
     Club,
     LineOfCredit
  }

I really don't care what values the compiler assigns to these enums. Sure I
could choose specific values but it doesn't really matter.
     
> having strings filled by ff's means that you will get problems
> of different kinds - partially initialized strings.

Huh???? Why would I always get partially initialized strings, as you imply?
And even if I did, then having 0xFF in them is going to help me track down
some stupid code that I wrote.

> Could you tell me do you ever had situation when
> ffffff strings helped you to find problem?

No. I haven't made that kind of mistake yet with my code.

> And if yes how it is in principle different from
> catching strings with 00000?

Because if I found a 0x00 in a string, I wouldn't know if its legitimate or
not.
 
> Can anyone here say that this fffffffs helped to find
> problem?

But if I found 0xFF I would know straight away that I've made a mistake
somewhere. Actually, come to think about it, I did make a mistake once when
my code was incorrectly interpreting a BOM in a text file. I loaded the
file as if was UTF-8 but it should have been UTF-16. DMD correctly told me
I had a bad UTF strings when I tried to write it out.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
2/08/2006 5:49:46 PM



More information about the Digitalmars-d mailing list