Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!huxley!steve From: steve@huxley.huxley.bitstream.com (Steve Stein) Newsgroups: comp.sys.mac.programmer Subject: Re: What's wrong with this??? Message-ID: Date: 5 Apr 91 14:08:37 GMT References: <1209@argosy.UUCP> Sender: steve@huxley.UUCP Reply-To: (Stephen Z. Stein) Organization: Bitstream, Inc. Lines: 38 In-reply-to: jay@argosy.UUCP's message of 4 Apr 91 20:55:47 GMT In article <1209@argosy.UUCP> jay@argosy.UUCP (Jay O'Conor) writes: > What is wrong with this statement? > > fprintf( logfile, (isascii(*cp) && isprint(*cp)) ? "[%c]" : [%02x]", *cp); > > The problem I'm having is the result of isprint() doesn't seem to be > working. *cp is defined as an unsigned char *. This is using MPW3.2b3 > (from the ETO CD-ROM). If I split the isascii() and isprint() out into > seperate lines, assigning their result to two temporary variables, then > logical and the two results in the fprintf line, then everything is > fine. Naturally, I'm not crazy about having two variables just to deal > with this. I wouldn't be surprised if this is just a bug in MPW. I recall a similar bug in THINK C (then LightspeedC) v1, which was fixed by v2 (or at least v3), having to do with register allocation in just this type of statement (a ternary expression with a compound Boolean in the first element). The complexity of the expression is compounded because isascii and isprint are macros (at least I think they are!) which themselves expand to logical expressions. One suggestion: maybe the macros are defined a bit wrong. Try changing the statement to: fprintf( logfile, ((isascii(*cp)) && (isprint(*cp))) ? "[%c]" : [%02x]", *cp); adding parens around the two macro invocations. The macros ought to have the parens in place already, but sometimes programmers get lazy. If this doesn't work, I think it's just a compiler bug. Let me know if the parens help! - Steve Stein