Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Newsgroups: comp.lang.c Subject: Re: Assignment in test: OK? Message-ID: <1990Sep14.141925.18163@druid.uucp> Date: 14 Sep 90 14:19:25 GMT References: <928@hls0.hls.oz> <18326@ultima.socs.uts.edu.au> Organization: D'Arcy Cain Consulting, West Hill, Ontario Lines: 29 In article <18326@ultima.socs.uts.edu.au> jeremy@sinope.socs.uts.edu.au (Jeremy Fitzhardinge) writes: >this is quite a useful construct. How many would prefer > if (thing != NULL) > { > fp = fopen(thing, "r"); > if (fp == NULL) > barf(); > } >to > if (thing && (fp = fopen(thing, "r")) > barf(); >? I think I prefer the former since the second version has a bug. I think you meant to say: if (thing && ((fp = fopen(thing, "r")) == NULL) and just as a matter of style I would use: if ((thing != NULL) && ((fp = fopen(thing, "r")) == NULL) And that solves the =/== problem as well. I suppose you may also have meant if ((thing == NULL) || ((fp = fopen(thing, "r")) == NULL) unless the 'file not named' error is handled elsewhere. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | MS-DOS: The Andrew Dice Clay West Hill, Ontario, Canada | of operating systems. + 416 281 6094 |