Geschrieben von:/Posted by: Ron Murawski at 26 June 2004 07:23:15:
Als Antwort auf:/In reply to: Re: More WBEC output examination... {LGPGNVER} geschrieben von:/posted by: Dieter Bürßner at 25 June 2004 23:05:54:
I agree with your suggestions. One minor point later
"I will always get correct data from the user." is an intentional oversight. So (for instance) if you are expecting a FEN position, and you get one megabyte of binary data instead, your program does bad things. The reason I call it an intentional oversight is that it is not reasonable to assume perfect input.
There are also unintentional oversights. For instance, you may assume that no board position has more than 255 distinct moves possible. After all, the maximum ever discovered is 218. But the reasonable assumption may be incorrect. Perhaps there is some strange position with 257 moves possible.
5. Always set your compiler to the highest warning level possible.
323 moves will be enough for legal chess positions. 9 Q, 2 R, 2 B, 2 N, 1 K
9*27+2*14+2*13+2*8+10 (including 2 castling moves).
It is clear, that the actual maximum will be quite a bit lower, but I see no (easy) way, to calculate it.
I find it a PITA, with for example MSVC.
My code gets many such warnings. With -W4 too many, to make it useful. The serious warnings will be easily overseen. I don't think it would be nice, to clutter the source code with many pragmas to disable specific warnings.
I have seen other examples about warnings, which go away with a cast, that is really unneeded, and that may easily break the code, when the type of the var is changed, but one forgets to change the cast.
Such warnings may make you write worse code.
>G:\src\yace>cat m.c
>extern void foo(void);
>extern void bar(void);
>
>#define robust_macro() do { foo(); bar(); } while (0)
>#define fragile_macro() {foo(); bar(); }
>void dummy(int i)
>{
> if (i<0)
> robust_macro(); /* won't work with fragile macro, but warning */
> else
> bar();
> fragile_macro(); /* No warning */
>}
>
>G:\src\yace>cl -W4 -c m.c
>Optimierender Microsoft (R) 32-Bit C/C++-Compiler, Version 12.00.8168, fuer x86
>Copyright (C) Microsoft Corp 1984-1998. Alle Rechte vorbehalten.
>m.c
>m.c(11) : warning C4127: Bedingter Ausdruck ist konstant
>(Conditional expression is constant)
>
Speaking of writing worse code...

do 
{ 
foo(); 
bar(); 
} while (0);
can be replaced by:
for (;;) // infinite loop
{
foo();
bar();
break; // break out of loop the first time thru...
}
It's ugly, but generates no Microsoft level4 warnings. The code optimizer seems to do okay on this as well.
Ron