www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/08/20:26:10

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: expression evaluation guarantees
Date: Fri, 08 Aug 1997 09:42:30 -0700
Organization: Alcyone Systems
Lines: 34
Message-ID: <33EB4C76.78E76FEB@alcyone.com>
References: <33EADE57 DOT F93 AT pentek DOT com>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Charles Krug wrote:

> To those of you who bit my head off (OUCH) consider the following, which
> came up last week:
> 
> if ((get_user_response()) && (format_hard_drive()))
>         printf("Hard drive formatted");
> 
> Are you willing to bet your hard drive that your compiler is ANSI
> complient?

I have yet to see _any_ ANSI C compiler that does not do short circuiting
properly.

So in the case of 

    if (get_user_response))
        format_hard_drive();

are you willing to bet that all compilers are ANSI compliant?  Same
question.  Equally stupid.

The short circuiting && and || operators were _introduced_ to C for their
short circuiting properties (before that bitwise & and | were just used).
They weren't introduced in ANSI C, or even K&R C, but in traditional C.
Short circuiting is about as built into the language as if statements.

-- 
       Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
   "Love is not love which alters / when it alteration finds."
                                 / William Shakespeare, _Sonnets_, 116

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019