Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!sunic!tut!ra!rosenber From: rosenber@ra.abo.fi (Robin Rosenberg INF) Newsgroups: comp.sys.amiga.tech Subject: &&,|| (was Re: Fonts and freeing memory) Message-ID: Date: 17 Jan 90 12:33:26 GMT References: <145@ccave.UUCP> <9001161446.AA29551@en.ecn.purdue.edu> Sender: rosenber@ra.abo.fi Organization: Abo Akademi University, Finland Lines: 22 In-reply-to: bevis@EE.ECN.PURDUE.EDU's message of 16 Jan 90 14:46:36 GMT >> >> if ((WinFont = (struct TextFont *) OpenFont (&ta)) == NULL && >> (WinFont = (struct TextFont *) OpenDiskFont (&ta)) == NULL) { >> Abort ("Can't open font\n"); >> } > >Well, I wouldn't do that either, because you can't be sure what the compiler >is going to do with your code. You've got two expressions hooked together >with a logical 'and' -- now which one will the final code try first? The one >on the right? Uh-oh. This is better: Anyone who knows C also knows that the logical operators && and || are GUARANTEED to evaluate left-right and only so far as to know the final result of the expression. I.e in "a && b", if a is false (0) the compiler knows that the expression is false and b isn't evaluated. If a is true b has to be evaluated to determine the value of the expression. This applies to C, C++ and Modula-2. ---------------- Robin Rosenberg