Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.std.c Subject: Re: switch (expression) Message-ID: <8255@brl-smoke.ARPA> Date: 29 Jul 88 02:48:47 GMT References: <1988Jul12.105547.13268@light.uucp> <755@vsi.UUCP> <59881@sun.uucp> <19876@watmath.waterloo.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 14 In article <19876@watmath.waterloo.edu> rbutterworth@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.