🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #2816

&&,|| (was Re: Fonts and freeing memory)

#2816
From: Robin Rosenberg INF
Date: Wed, 17 Jan 1990 12:33
22 lines
1852 bytes
>>                                                                            
>>    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
Technical Details
Message-ID: <ROSENBER.90Jan17143326@ra.abo.fi>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!sunic!tut!ra!rosenber
References: <145@ccave.UUCP> <9001161446.AA29551@en.ecn.purdue.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <ROSENBER.90Jan17143326@ra.abo.fi>
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