switch (expression)

Doug Gwyn gwyn at brl-smoke.ARPA
Fri Jul 29 12:48:47 AEST 1988


In article <19876 at watmath.waterloo.edu> rbutterworth at watmath.waterloo.edu (Ray Butterworth) writes:
>and too often I've seen code that tests the value with
>something like:       if ((int)function() == -1) ...
>This happens to work sometimes, but it is still wrong.
>It should be:         if (function() == (type*)-1) ...

Nope, neither of these is necessarily going to work.
That's why it's a poor idea in the first place.

The -1 value is really set up by the common library
error module AS AN INTEGER return value.  There is
no guaranteed portable way to pick this up without
damaging it or losing the ability to correctly capture
the non-error return value.  You can try using a union
for this but I still doubt that it will always work.



More information about the Comp.std.c mailing list