Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Assignment in test: OK? Message-ID: <26502@mimsy.umd.edu> Date: 12 Sep 90 07:04:52 GMT References: <1990Sep5.185451.25532@DRD.Com> <18326@ultima.socs.uts.edu.au> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 44 In article <18326@ultima.socs.uts.edu.au> jeremy@sinope.socs.uts.edu.au (Jeremy Fitzhardinge) writes: [??? .edu.au ???] >... How many would prefer > if (thing != NULL) > { > fp = fopen(thing, "r"); > if (fp == NULL) > barf(); > } >to > if (thing && (fp = fopen(thing, "r")) > barf(); >? I would, along with most compilers: the second version has an unclosed left parenthesis. :-) Anyway, I would (and often do) rewrite examples like the latter as if (thing && (fp = fopen(thing, "r")) != NULL) barf(); or if (thing != NULL && (fp = fopen(thing, "r")) != NULL) barf(); (NB: this is what the second quoted example does when the missing close paren is added, and differs from what the first quoted example does. In pseudo-code, this is if we have a filename and the file can be read call barf while the first quoted example is if we have a file name, but the file cannot be read call barf As usual, when making code concise you must be sure to keep it correct.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris