Posts

Showing posts with the label WTF

Guess the output of this program.

Guess the output of this program. Is this three Delphi bugs for the price of one? Compiler mentions:  [dcc32 Hint] WeirdCaseConstruct.dpr(11): H2077 Value assigned to 'Handled' never used 1. If statement inside case - after ELSE option? 2. Handled is actually used 3. else Test(4) is never called #wtf  XE7.1 (32-bit, Windows) program WeirdCaseConstruct; {$APPTYPE CONSOLE} {$R *.res} uses   System.SysUtils; procedure Test(const Value: Integer); var   Handled: Boolean; begin   Handled := True; //   case Value of     1: writeln('One');     2: writeln('Two');     else Handled := False;     if not Handled      then Writeln(Value, ' is unhandled')       else Test(4);   end; end; begin   Test(1);   Test(3);   Write('Press Enter');   Readln; end.

True or False or False = False!

Image
True or False or False = False! (True or False or False) = True. function TPSDConnectionMonitor.IsOnline: Boolean; var   cState: TPSDConnectionState; begin   Result := (Not OfflineStoreEnabled) or (Not Enabled) or IsOnline(cState); end; See the picture.   FOfflineStoreEnabled = False FEnabled = True IsOnline(cState) does an and between two states and returns False The expression  (Not OfflineStoreEnabled) or (Not Enabled) or IsOnline(cState) is (True) or (False) or False and Result is False! #WTF   Add extra paranthesis to the expression  ( (Not OfflineStoreEnabled) or (Not Enabled) or IsOnline(cState)) is ((True) or (False) or False) and Result is True as expected! Can someone make sense of this? #XE5