Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

Warning: Unreachable code. Why?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

In my browserdetection code I have this:

const
  OS_HAS_DEFAULT_BROWSER = {$IFDEF WINDOWS}True{$ELSE}False{$ENDIF};
When I compile my program I get this warning:
"browserdetection.pp(187,34) Warning: unreachable code"

line 187 ->

  if OS_HAS_DEFAULT_BROWSER then Exit;

(the cursor then blinks on the E in Exit (position 34))

Why is this?

Bart

Reply by email

Brad Campbell
to Bart
Bart wrote 13 lines
In my browserdetection code I have this: const OS_HAS_DEFAULT_BROWSER = {$IFDEF WINDOWS}True{$ELSE}False{$ENDIF}; When I compile my program I get this warning: "browserdetection.pp(187,34) Warning: unreachable code" line 187 -> if OS_HAS_DEFAULT_BROWSER then Exit; (the cursor then blinks on the E in Exit (position 34)) Why is this?

Because if OS_HAS_DEFAULT_BROWSER = false then the compiler will optimise the if call away (as it can never actually execute) and the "Exit" can never be reached.

You would be just as effective using

{$IFDEF WINDOWS}
   Exit;
{$ENDIF}

Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Bart
to Brad Campbell
Because if OS_HAS_DEFAULT_BROWSER = false then the compiler will optimise the if call away (as it can never actually execute) and the "Exit" can never be reached.

Ah, now I see.

Show quoted text 6 lines
You would be just as effective using {$IFDEF WINDOWS} Exit; {$ENDIF}

Yep.

Thanks for the explanation!

Bart

Reply by email