> As the comments clearly state, its using -1 to represent an 
> unused entry,
> which the compiler turns into an 'all ones' regardless of the 
> size of the
> target unsigned value. So, if the size of the unsigned value 
> changes, it
> will still always be set to 'all one' bits. Its not a bug, in 
> that it was
> intentionally done that way. AFAIK, the compilers we use don't have a
> problem with this common operation. However, if its causing 
> compile errors,
> I will change it to use a fixed unsigned value.

been a while since my bit twiddling days, but I think ~((unsigned)0) or ~0u
(complement of unsigned 0) will do the same trick with fewer compilers
complaining...

- James
 
> ----------------------------------------
> Dean Roddey
> Software Weenie
> IBM Center for Java Technology - Silicon Valley
> [EMAIL PROTECTED]
> 
> 
> 
> Craig Noah <[EMAIL PROTECTED]>@sterling.com on 
> 03/07/2000 07:47:31 AM
> 
> Please respond to [EMAIL PROTECTED]
> 
> Sent by:  [EMAIL PROTECTED]
> 
> 
> To:   [EMAIL PROTECTED]
> cc:
> Subject:  bug swatting: -1 assigned to array of unsigned int
> 
> 
> 
> Can someone explain the following code to me? It comes from
> DFAContentModel.cpp, lines 744 through 755.  Specifically, why is -1
> being assigned to an array of unsigned ints?
> 
> Here is the code:
> //
> //  -1 is used to represent bad transitions in the transition table
> entry for
> //  each state. So each entry is initialized to an all -1 array. This
> method
> //  creates a new entry and initializes it.
> //
> unsigned int* DFAContentModel::makeDefStateList() const
> {
>     unsigned int* retArray = new unsigned int[fElemMapSize];
>     for (unsigned int index = 0; index < fElemMapSize; index++)
>         retArray[index] = -1;
>     return retArray;
> }
> 
> --
> Craig Noah                 INTERNET: [EMAIL PROTECTED]
> Software Engineer
> 
>                 Sterling Software ITD
> 1404 Fort Crook Road South     Phone:    (402) 291-8300 x 284
> Bellevue,  NE   68005-2969     FAX:      (402) 291-4362
> 
> 
> 

Reply via email to