[M3devel] Posix < 0 vs. # 0 vs. = -1?

Mika Nystrom mika at async.async.caltech.edu
Sun Apr 18 21:41:59 CEST 2010


Jay K writes:
>--_201b8a99-e8e8-4887-bb32-c65e8edd0b1a_
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>
>Posix often says:
>
> function foo() returns 0 for success=2C -1 for error
>
>=20
>
> m3core/libm3/etc=2C often say if foo() < 0 or if foo() # 0 "instead".
> Generally ok to tighten these up to "=3D -1"=2C perhaps upon checking manp=
>ages=2C
>  or a known rat's nest of inconsistencies?
>

Maybe this is just my personal style, but I would code it thus:

<*EXTERNAL*>
PROCEDURE F() : INTEGER; (* matches C declaration *)

...

VAR result : [0..1] := F(); (* matches man page specification *)
BEGIN
  CASE result OF 
    0 => ...
  |   
   -1 => ...
  END
END
   
No way for any sneaky value problems to get through.  The use of
CASE also guards against typos.

    Mika



More information about the M3devel mailing list