Mail Archives: djgpp/1997/08/07/11:49:17

Date: Thu, 07 Aug 1997 17:46:47 +0200
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Subject: Re: [Q] expression evaluation order
To: xfesenko AT pacific DOT net DOT sg (Victor)
Cc: djgpp AT delorie DOT com
Message-id: <01IM60KCNPZE8WW0BY@mail>
Organization: RWTH Aachen, III. physikalisches Institut B
Newsgroups: comp.os.msdos.djgpp

In article <5sbb1h$kvr$1 AT newton DOT pacific DOT net DOT sg> you wrote:
> Is it safe to assume that the expression 

> if(first_function()==OK && second_function()==OK &&
> third_function()==OK) return(OK);

> will be evaluated from left to right?

In contrast to the other answer I just had to see in the newsgroup:
*Yes*, this behaviour is even guaranteed by the ANSI C Standard,
and it was like that even before the Standard was written.

The so called 'short-circuiting' of logical expressions is what 
requires the fixed order of evaluation of terms here:

   if first_function() did *not* return 'OK', then none
      of the other functions need to be called: the result of
      the expression is 'false' anyway. So they won't be called.


- Raw text -

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