Uninitialized static int counters?
    Kevin D. Clark 
    kevin_d_clark at comcast.net
       
    Fri Feb  6 15:49:38 EST 2009
    
    
  
Michael ODonnell writes:
> Yes.  Right.  Sheesh, thanks a bunch, guys but I get the CompSci101
> stuff (I've *written* compilers and kernels) I just ask questions
> like these in public to keep discussion flowing, and I remarked
> about that blindly-cranking-the-counter-til-it-wraps situation
> because it was, um, remarkable (to me) how b0rken/clumsy it seems.
This reminds me of people who are trying to keep all of the unique
lines in a file, and keep them in order too, who write:
  perl -ne 'print if (!$seen{$_}++)' somefile.txt
I occasionally try to point out that this code is in fact incorrect.
Here is one way to make the code correct:
  perl -ne 'print if (!defined($seen{$_})); $seen{$_}=1;' somefile.txt
Sure, the first method "looks cooler" but I come from the "it must be
correct" camp.
Regards,
--kevin
-- 
GnuPG ID: B280F24E                Meet me by the knuckles
alumni.unh.edu!kdc                of the skinny-bone tree.
http://kdc-blog.blogspot.com/     -- Tom Waits
    
    
More information about the gnhlug-discuss
mailing list